A
太简单,写完删了
B
我写的繁了,但是意思是这么个意思,就遍历打擂台一样,找到最后的胜者,然后在遍历一遍找是不是最厉害的
#include <bits/stdc++.h>
using namespace std;
#define int long long
int op[200095][16];
signed main()
{int t;cin >> t;while (t--){int n;cin >> n;int k = -1;int maxn[6];memset(maxn, 0x3f3f3f3f, sizeof(maxn));int ch[6];for (int j = 1; j <= n; j++){int cou = 0;for (int i = 0; i < 5; i++){cin >> ch[i];op[j][i] = ch[i];if (ch[i] < maxn[i])cou++;}if (cou >= 3){for (int i = 0; i < 5; i++){maxn[i] = ch[i];}k = j;}}bool flag = true;for (int i = 1; i <= n; i++){int cou = 0;if (i != k)for (int j = 0; j < 5; j++){if (maxn[j] < op[i][j])cou++;}elsecou = 5;if (cou < 3){flag = false;break;}}if (flag)cout << k << endl;elsecout << -1 << endl;}
}
D
别人代码,直接拿来用了
应该是最精简的了
#include<bits/stdc++.h>
using namespace std;
map<int,int> mp;
int a[101000];
int n,flag = 0;
void dfs(int now,int all)
{if(now == n){if(mp[all]!=0){flag = 1;}mp[all] ++;return ;}now ++;dfs(now,all + a[now]);dfs(now,all);
}
int main()
{int T;scanf("%d",&T);while(T--){scanf("%d",&n);for(int i = 1;i<=n;i++){scanf("%d",&a[i]);}mp.clear();flag = 0;dfs(0,0);if(flag){printf("YES\n");}else{printf("NO\n");}}
}
tourist代码:
思路一个数可以取或者取反例,或者不取
#include <bits/stdc++.h>
using namespace std;
int main() {ios::sync_with_stdio(false);cin.tie(0);int tt;cin >> tt;while (tt--) {int n;cin >> n;vector<int> a(n);for (int i = 0; i < n; i++) {cin >> a[i];}int p3 = 1;for (int i = 0; i < n; i++) {p3 *= 3;}bool found = false;for (int t = 1; t < p3; t++) {int tmp = t;int sum = 0;for (int i = 0; i < n; i++) {int d = tmp % 3;if (d == 1) sum += a[i];if (d == 2) sum -= a[i];tmp /= 3;}if (sum == 0) {found = true;break;}}cout << (found ? "YES" : "NO") << '\n';}return 0;
}