A. Computer Game
Problem - A - Codeforces (Unofficial mirror site, accelerated for Chinese users)
/*//
Problem: A. Computer Game
Contest: CF115
URL: https://codeforces.ml/contest/1598/problem/A
/*/
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
using namespace std;
const int inf = 0x3f3f3f3f;
const ll ll_inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 5;
int main(int argc, char const *argv[]) {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T;
cin >> T;
while (T --) {
int n;
string s1, s2;
cin >> n >> s1 >> s2;
bool ok = true;
for (int i = 0; i < n; i ++) {
if (s1[i] == '1' && s2[i] == '1') {
ok = false;
break;
}
}
if (ok) {
puts("YES");
} else {
puts("NO");
}
}
return 0;
}
B. Groups
Problem - B - Codeforces (Unofficial mirror site, accelerated for Chinese users)
/*//
Problem: B. Groups
Contest: CF115
URL: https://codeforces.ml/contest/1598/problem/B
/*/
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
using namespace std;
const int inf = 0x3f3f3f3f;
const ll ll_inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 5;
int main(int argc, char const *argv[]) {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T;
cin >> T;
while (T --) {
int n;
cin >> n;
vector<int > a[n + 1];
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= 5; j ++ ) {
int tmp;
cin >> tmp;
a[i].push_back(tmp);
}
}
vector<int > b[5];
for (int i = 0; i <= 4; i ++) {
for (int j = 1; j <= n; j ++) {
if (a[j][i] == 1) {
b[i].push_back(j);
}
}
}
// for(int i = 0; i <= 4; i ++) {
// for(int j = 0; j < b[i].size(); j ++) {
// cout <<b[i][j] << " ";
// }
// cout << endl;
// }
vector<int > ok;
for (int i = 0; i <= 4; i++) {
if (b[i].size() >= n / 2) {
ok.push_back(i);
}
}
// for(int i = 0; i < ok.size(); i ++) {
// cout <<ok[i] << " ";
// }
// cout << "ok" << endl;
if (ok.size() < 2) {
cout << "NO" << endl;
} else {
bool flag = false;
for (int i = 0; i < ok.size(); i ++) {
for (int j = 0; j < ok.size(); j ++) {
bool flag1 = true;
if (j == i) {
continue;
}
// cout << ok[i] << " " << ok[j] << " " << "ok" <<endl;
for (int k = 1; k <= n; k ++) {
if (!a[k][ok[i]] && !a[k][ok[j]]) {
flag1 = false;
break;
}
}
if (flag1) {
flag = true;
}
}
}
if (flag) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
return 0;
}
C. Delete Two Elements
Problem - C - Codeforces (Unofficial mirror site, accelerated for Chinese users)
/*//
Problem: C. Delete Two Elements
Contest: CF115
URL: https://codeforces.ml/contest/1598/problem/C
/*/
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
using namespace std;
const int inf = 0x3f3f3f3f;
const ll ll_inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 5;
int main(int argc, char const *argv[]) {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T;
cin >> T;
while (T --) {
int n;
cin >> n;
double sum = 0;
double k = 0;
vector<double > a(n + 1);
map<double, int > vis;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
vis[a[i]] ++;
sum += a[i];
}
k = sum * 1.0 / n;
ll ans = 0;
for (int i = 1; i <= n; i ++) {
vis[a[i]] --;
double d = (double)(a[i] - k);
if (vis[k - d]) {
ans += vis[k - d];
}
}
cout << ans << endl;
}
return 0;
}
这个题当时没有写出来, 看都没有看懂, 后面看一下 ,就是一个交互题, 就是测试数据难弄一些 其他就是一个巧妙的 1 —— n 推算, 用 + i 和+ 1 确定每一位数就好。
/*//
Problem:
Contest:
URL:
/*/
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
using namespace std;
const int inf = 0x3f3f3f3f;
const ll ll_inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 5;
int main(int argc, char const *argv[]) {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
vector<int > p(n + 1);
for (int i = 2; i <= n; i ++) {
cout << "? ";
for (int j = 1; j < n; j ++) {
cout << i << " ";
}
cout << 1 << endl;
int idx;
cin >> idx;
p[idx] = 1 - i;
}
for (int i = 2; i <= n; i ++) {
cout << "? ";
for (int j = 1; j < n; j ++) {
cout << 1 << ' ';
}
cout << i << endl;
int idx;
cin >> idx;
p[idx] = i - 1;
}
int min_c = inf;
for(int i = 1; i <= n; i ++) {
min_c = min(min_c, p[i]);
}
p[n] = abs(min_c) + 1;
for (int i = n-1; i >= 1; i --) {
p[i] = p[n] + p[i];
}
cout << "! ";
for(int i = 1; i <= n; i ++) {
cout << p[i] << " ";
}
cout << endl;
return 0;
}