Educational codeforces round 83 Div2 B(sort)
程序员文章站
2022-06-04 18:18:31
...
B. Bogosort
题意:
- 要你进行操作,使数列,满足每一项是这个关系 j−aj≠i−ai
(j>i)
思路:
仔细一看看不出什么,就变一下形:
- j-i ≠ aj-ai。那么就要去构造。
- 当一个数列从小到大排序之后,就满足了。
- j-i>0 && aj-ai<=0
AC
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[110];
bool cmp(int a, int b)
{
return a>b;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i=1; i<=n; i++)cin>>a[i];
sort(a+1,a+1+n,cmp);
for(int i=1; i<=n; i++)cout<<a[i]<<' ';
cout<<endl;
}
return 0;
}
上一篇: 新百胜公司开户scc2339
下一篇: 想要实现这样的读取数据库的功能,怎么做
推荐阅读
-
Educational Codeforces Round 93 (Rated for Div. 2) B - Substring Removal Game
-
B. Amr and Pins (Codeforces Round #287 (div2))
-
Codeforces Round #264 (div2)B. Caisa and Pylons
-
B. Friends and Presents(Codeforces Round #275(div2)
-
Codeforces Round #258 (Div. 2) B. Sort the Array (模拟)
-
Codeforces Round #264 (div2)B. Caisa and Pylons
-
Educational Codeforces Round 83 (Rated for Div. 2) D. Count the Arrays
-
[Educational Codeforces Round 87 (div2)]1354
-
Educational codeforces round 83 Div2 B(sort)
-
【Educational Codeforces Round 80(div2)】E-Messenger Simulator (树状数组)