#include <vector> #include <cstdio> #include <algorithm> using namespace std; int T[100010][4],N[100010],n; bool cmp0(int a,int b){return T[a][0]<T[b][0];} bool cmp1(int a,int b){return T[a][1]>T[b][1];} bool cmp2(int a,int b){return T[a][2]<T[b][2];} bool cmp3(int a,int b){return T[a][3]>T[b][3];} bool (*F[])(int,int)={cmp0,cmp1,cmp2,cmp3}; int main() { int ts,k; scanf("%d",&ts); while(ts--) { scanf("%d",&n); for(int i=0;i<n;++i) { N[i]=i; scanf("%d %d %d %d",&T[i][0],&T[i][1],&T[i][2],&T[i][3]); } for(int i=0;i<4;++i) { sort(N,N+n,F[i]); k=1; while(k<n and T[N[k]][i]==T[N[0]][i]){T[N[k]][i]=-1; ++k;} T[N[0]][i]=-1; } k=0; for(int i=0;i<n;++i) if(T[i][0]+T[i][1]+T[i][2]+T[i][3] == -4) { k=1; break; } puts(k?"TAK":"NIE"); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include <vector> #include <cstdio> #include <algorithm> using namespace std; int T[100010][4],N[100010],n; bool cmp0(int a,int b){return T[a][0]<T[b][0];} bool cmp1(int a,int b){return T[a][1]>T[b][1];} bool cmp2(int a,int b){return T[a][2]<T[b][2];} bool cmp3(int a,int b){return T[a][3]>T[b][3];} bool (*F[])(int,int)={cmp0,cmp1,cmp2,cmp3}; int main() { int ts,k; scanf("%d",&ts); while(ts--) { scanf("%d",&n); for(int i=0;i<n;++i) { N[i]=i; scanf("%d %d %d %d",&T[i][0],&T[i][1],&T[i][2],&T[i][3]); } for(int i=0;i<4;++i) { sort(N,N+n,F[i]); k=1; while(k<n and T[N[k]][i]==T[N[0]][i]){T[N[k]][i]=-1; ++k;} T[N[0]][i]=-1; } k=0; for(int i=0;i<n;++i) if(T[i][0]+T[i][1]+T[i][2]+T[i][3] == -4) { k=1; break; } puts(k?"TAK":"NIE"); } } |