0
点赞
收藏
分享

微信扫一扫

div 794

NicoalsNC 2022-07-13 阅读 61

​​https://codeforces.com/contest/1686​​

A

思路:数据量很小,100这样,直接暴力模拟O(n²)



/*
给你1--n,在你看了电影后,你站起来进行如下操作
操作1,你选择n-1个元素,替换掉他们成为他们的算数平均值
*/
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn = 50 + 5;

int a[maxn] = {};

void s(){
int n;
cin >> n;

for(int i = 1; i <= n; i++) cin >> a[i];

sort(a+1, a+n+1);

double sum = 0;
for(int i = 1; i <= n ;i ++){
sum = 0;
for(int j = 1; j <= n ;j ++){
if(j != i){
sum += a[j];
}
}
sum /= (n - 1);
if(sum == a[i]){
cout << "YES\n";
return ;
}

}

cout << "NO\n";
}

int main(){

ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#ifdef LOCAL
FILE *p = fopen("input.txt", "a+");
fclose(p);
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while(t--) s();


return 0;
}

B

思路:这题是要连续分割,不是挑出子区间。所以就找有几个断层点就行。比如345612,6与1之间就是断层。遇到断层就i+=2就行,继续往下分割


/*
一个序列,定义1--m中,bi》bj逆序,这样的逆序对总数是奇数的就叫奇
*/
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn = 1e5 + 5;

void s(){
int n ;
cin >> n;
int a[maxn] = {};
memset(a, 0x3f, sizeof a);
for(int i = 1; i <= n;i ++) cin >> a[i];

long long ans = 0;
for(int i = 1; i <= n; i ++){
if(a[i] > a[i + 1]){
ans ++;
i++;
}
}

cout << ans <<endl;
}

int main(){

ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#ifdef LOCAL
FILE *p = fopen("input.txt", "a+");
fclose(p);
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >>t;
while(t--) s();


return 0;
}

C

思路:稍微模拟一下。先排序,将整个数组从中切开,将前半部分分别放入13579..的位置,将后半部分放入2468...的位置,check是否满足奇数下标的小  偶数下标的大


/**/
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn = 1e5 + 5;

int n;
int a[maxn];
int ans[maxn];

bool check(){

if(ans[1] >= ans[n] || ans[n] <= ans[n - 1])
return 0;

for(int i = 2; i <= n - 2;i += 2){
if(ans[i] <=ans[i - 1] || ans[i] <= ans[i + 1]){
return 0;
}
}
return 1;
}

void s(){
cin >> n;

for(int i = 1; i <= n; i ++) cin >> a[i];

if(n % 2 == 0){
sort(a+1, a+1+n);
for(int i = 1, j = 1, k = n / 2 + 1; i <= n; i += 2){
ans[i] = a[j++];
ans[i + 1] = a[k++];
}
if(check()){
cout << "YES\n";
for(int i = 1; i <= n ;i ++) cout << ans[i] << " "; cout <<endl;
}else cout << "NO\n";
}else if(n % 2 == 1){
cout << "NO\n";
}



}

int main(){

ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#ifdef LOCAL
FILE *p = fopen("input.txt", "a+");
fclose(p);
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t; cin >> t;
while(t--) s();


return 0;
}

举报

相关推荐

0 条评论