#include<cstdio> #include<algorithm> #include<cmath> const int MAX=2000000002; struct sq{ int x; int y; int d=0; }; bool compX (sq* i,sq* j) { if(i->x == j->x){return (i->y < j->y);}else { return (i->x < j->x); } } bool compY (sq* i,sq* j) { if(i->y == j->y){return (i->x < j->x);}else { return (i->y < j->y); } } int odl(sq *i, sq* j){ int x=std::abs(i->x-j->x); int y=std::abs(i->y-j->y); if(y > x) x=y; return x; } bool cross(sq *i, sq* j){ int x=std::abs(i->x-j->x); int y=std::abs(i->y-j->y); if(y > x) x=y; return false; } sq t[2002]; sq* X[2002]; sq* Y[2002]; int ind[2002]; int main(){ int z, n, x, y; scanf("%d", &z); while(z--){ scanf("%d", &n); for(int i=0; i < n; ++i){ scanf("%d %d", &x, &y); t[i].x=x; t[i].y=y; X[i]=&t[i]; Y[i]=&t[i]; } std::sort(X,X+n,compX); std::sort(Y,Y+n,compY); int minY=Y[0]->y; int minX=X[0]->x; int maxX=0; int maxY=0; int indexOfCorner=0; for(int i=0; i < n; ++i){ int d=MAX; for(int j=i+1; j < n; ++j){ if(X[i]->y <= X[j]->y){ int tmp = odl(X[i],X[j]); if(tmp < d) d=tmp; } } X[i]->d=d; if(d!=MAX){ if(maxX < (X[i]->x + d)){ maxX = (X[i]->x + d); } if(maxY < (X[i]->y + d)){ maxY = (X[i]->y + d); } }else{ ind[indexOfCorner]=i; indexOfCorner++; } } for(int i=0; i < indexOfCorner; ++i){ X[ind[i]]->d=std::max((maxX-X[ind[i]]->x),(maxY-X[ind[i]]->y)); if(X[ind[i]]->d==0 || X[ind[i]]->d==MAX){ //printf("%d --- %d %d\n", ind[i], maxX, maxY); printf("NIE\n"); continue; }else{ //printf("%d --- %d %d\n", ind[i], maxX, maxY); if(maxX < (X[ind[i]]->d + X[ind[i]]->x)){ maxX = (X[ind[i]]->d + X[ind[i]]->x); } if(maxY < (X[ind[i]]->d + X[ind[i]]->y)){ maxY = (X[ind[i]]->d + X[ind[i]]->y); } } } long long int field=(maxX-minX)*(maxY-minY); //printf("%lld --min:- %d %d max: %d %d", field, minX, minY, maxX, maxY); for(int i=0; i < n; ++i){ int d=X[i]->d; field-=d*d; } if(field!=0){ printf("NIE\n"); continue; } bool check=false; for(int i=0; i < n; ++i){ for(int j=0; j < n; ++j){ if(i!=j){ if(cross(X[i],X[j])){ check=true; } } } } if(check){ printf("NIE\n"); continue; } printf("TAK "); for(int i=0; i < n; ++i){ int d=t[i].d; printf("%d ", d); } printf("\n"); } }
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | #include<cstdio> #include<algorithm> #include<cmath> const int MAX=2000000002; struct sq{ int x; int y; int d=0; }; bool compX (sq* i,sq* j) { if(i->x == j->x){return (i->y < j->y);}else { return (i->x < j->x); } } bool compY (sq* i,sq* j) { if(i->y == j->y){return (i->x < j->x);}else { return (i->y < j->y); } } int odl(sq *i, sq* j){ int x=std::abs(i->x-j->x); int y=std::abs(i->y-j->y); if(y > x) x=y; return x; } bool cross(sq *i, sq* j){ int x=std::abs(i->x-j->x); int y=std::abs(i->y-j->y); if(y > x) x=y; return false; } sq t[2002]; sq* X[2002]; sq* Y[2002]; int ind[2002]; int main(){ int z, n, x, y; scanf("%d", &z); while(z--){ scanf("%d", &n); for(int i=0; i < n; ++i){ scanf("%d %d", &x, &y); t[i].x=x; t[i].y=y; X[i]=&t[i]; Y[i]=&t[i]; } std::sort(X,X+n,compX); std::sort(Y,Y+n,compY); int minY=Y[0]->y; int minX=X[0]->x; int maxX=0; int maxY=0; int indexOfCorner=0; for(int i=0; i < n; ++i){ int d=MAX; for(int j=i+1; j < n; ++j){ if(X[i]->y <= X[j]->y){ int tmp = odl(X[i],X[j]); if(tmp < d) d=tmp; } } X[i]->d=d; if(d!=MAX){ if(maxX < (X[i]->x + d)){ maxX = (X[i]->x + d); } if(maxY < (X[i]->y + d)){ maxY = (X[i]->y + d); } }else{ ind[indexOfCorner]=i; indexOfCorner++; } } for(int i=0; i < indexOfCorner; ++i){ X[ind[i]]->d=std::max((maxX-X[ind[i]]->x),(maxY-X[ind[i]]->y)); if(X[ind[i]]->d==0 || X[ind[i]]->d==MAX){ //printf("%d --- %d %d\n", ind[i], maxX, maxY); printf("NIE\n"); continue; }else{ //printf("%d --- %d %d\n", ind[i], maxX, maxY); if(maxX < (X[ind[i]]->d + X[ind[i]]->x)){ maxX = (X[ind[i]]->d + X[ind[i]]->x); } if(maxY < (X[ind[i]]->d + X[ind[i]]->y)){ maxY = (X[ind[i]]->d + X[ind[i]]->y); } } } long long int field=(maxX-minX)*(maxY-minY); //printf("%lld --min:- %d %d max: %d %d", field, minX, minY, maxX, maxY); for(int i=0; i < n; ++i){ int d=X[i]->d; field-=d*d; } if(field!=0){ printf("NIE\n"); continue; } bool check=false; for(int i=0; i < n; ++i){ for(int j=0; j < n; ++j){ if(i!=j){ if(cross(X[i],X[j])){ check=true; } } } } if(check){ printf("NIE\n"); continue; } printf("TAK "); for(int i=0; i < n; ++i){ int d=t[i].d; printf("%d ", d); } printf("\n"); } } |