我是靠谱客的博主 痴情野狼,这篇文章主要介绍B. Shifting Sort (思维),现在分享给大家,希望可以做个参考。

思路大家都能想到,代码不是很好写

// Problem: B. Shifting Sort
// Contest: Codeforces - Codeforces Round #744 (Div. 3)
// URL: https://codeforces.com/contest/1579/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)
const int N=55;
int n;
int a[N],f[N];
struct node {
int a,b,c;
}v[N];
void solve()
{
scanf("%d", &n);
rep(i,1,n) cin >> a[i];
f[1] = a[1];
int ans = 0;
rep(i,2,n)
{
int p = n+1;
rep(j,1,i-1)
{
if(f[j] > a[i]){p = j; break;}
}
if(p == n+1) f[i] = a[i];
else
{
v[ans++] = {p,i,i-p};
int x = a[i];
fep(j,p,i-1) f[j+1] = f[j];
f[p] = x;
}
}
if(ans == 0) cout << 0 << endl;
else
{
cout << ans << endl;
for(int i = 0; i < ans; i++)
cout << v[i].a << " " << v[i].b << " " << v[i].c << endl;
}
}
int main()
{
int Case;scanf("%d", &Case);
while(Case--)
solve();
return 0;
}

最后

以上就是痴情野狼最近收集整理的关于B. Shifting Sort (思维)的全部内容,更多相关B.内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(144)

评论列表共有 0 条评论

立即
投稿
返回
顶部