题意:5 组数,每组 200 个以内,问能不能在每组里找一个使这 5 个数和为 0 。
这题太快看题解了。。多想想完全有可能做出来。。
先不写思路了,看以后看到这篇能不能相处来。。
代码:
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 220;
LL st[5][maxn];
LL cb1[maxn*maxn], cb2[maxn*maxn];
int main()
{
int N;
for(cin >> N; N; N--) {
int n;
cin >> n;
for(int i = 0; i < 5; i++)
for(int j = 0; j < n; j++)
cin >> st[i][j];
for(int i = 0, cnt = 0; i < n; i++)
for(int j = 0; j < n; j++)
cb1[cnt++] = st[0][i] + st[1][j];
for(int i = 0, cnt = 0; i < n; i++)
for(int j = 0; j < n; j++)
cb2[cnt++] = st[2][i] + st[3][j];
sort(cb1, cb1+n*n); sort(cb2, cb2+n*n);
bool ok = false;
for(int i = 0; i < n; i++) {
LL cur;
int pt1 = 0, pt2 = n*n-1;
while(pt1 < n*n && pt2 >= 0 && (cur = cb1[pt1] + cb2[pt2] + st[4][i])) {
if(cur > 0) pt2--;
else pt1++;
}
if(cur == 0) {
ok = true;
break;
}
}
cout << (ok ? "Yes" : "No") << endl;
}
return 0;
}