// to nie działa #include <cstdio> #include <cassert> #include <map> #include <vector> #include <algorithm> #include <list> #define MAKS 2100 #define ZADUZO 2000000001u #define f first #define s second #define mp make_pair using namespace std; typedef pair<int,int> para; typedef unsigned int uint; typedef long long int lld; int n; vector<para> v; int naj; int kwadrat[MAKS]; bool dasie(int ind, uint r) { if(r==0)return true; //printf("%d moze %u?\n",ind,r); for(int i=0;i<n;i++) { if(i==ind)continue; if(v[i].f>=v[ind].f && v[i].f<v[ind].f+r && v[i].s>=v[ind].s && v[i].s<v[ind].s+r)return false; if(kwadrat[i]==0)continue; if(((v[ind].f> v[i].f && v[ind].f < v[i].f+kwadrat[i]) || (v[ind].f+r> v[i].f && v[ind].f+r < v[i].f+kwadrat[i])) && ((v[ind].s> v[i].s && v[ind].s < v[i].s+kwadrat[i]) || (v[ind].s+r> v[i].s && v[ind].s+r < v[i].s+kwadrat[i]))) return false; } //puts("PEWKA"); return true; } bool ok() { if(n==1) { kwadrat[0]=1; return true; } for(int i=0;i<n;i++) { if(v[i].s<v[0].s)return false; } vector<int> pozostale; for(int i=0;i<n;i++)pozostale.push_back(i); while(pozostale.size()>1) { int ile=0; //printf("zostalo: %d\n",pozostale.size()); vector<int> akt; for(int i=0;i<pozostale.size();i++)akt.push_back(pozostale[i]); pozostale.clear(); for(int ind: akt) { uint pocz=0; uint kon=ZADUZO; while(pocz<kon) { uint sr=(pocz+kon+1)/2; if(dasie(ind,sr))pocz=sr; else kon=sr-1; } if(pocz==0)return false; else if(pocz==ZADUZO)pozostale.push_back(ind); else { kwadrat[ind]=pocz; //printf("%d dostaje %d\n",ind,pocz); ile++; } } //fprintf(stderr,"benc\n"); if(ile==0)break; } uint maksx=0; uint maksy=0; for(int i=0;i<n;i++) { uint kandx=v[i].f+kwadrat[i]; uint kandy=v[i].s+kwadrat[i]; if(kandx>maksx)maksx=kandx; if(kandy>maksy)maksy=kandy; } if(pozostale.size()>=1) { for(int ind: pozostale) { //printf("maksx: %u, maksy: %u\n",maksx,maksy); int kandr=maksx-v[ind].f; if(maksy-v[ind].s>kandr)kandr=maksy-v[ind].s; if(!dasie(ind,kandr))return false; kwadrat[ind]=kandr; //printf("%d dostaje ostatecznie %d\n",ind,kandr); if(v[ind].f+kandr>maksx)maksx=v[ind].f+kandr; if(v[ind].s+kandr>maksy)maksy=v[ind].s+kandr; } } // ostateczny sprawdzian lld pole1=lld(maksx-v[0].f)*lld(maksy-v[0].s); lld pole2=0; for(int i=0;i<n;i++) { pole2+=lld(kwadrat[i])*lld(kwadrat[i]); } //printf("%lld vs %lld\n",pole1,pole2); return pole1==pole2; } int orx[MAKS]; int ory[MAKS]; int main() { int t; scanf("%d",&t); while(t--) { scanf("%d",&n); v.clear(); naj=0; for(int i=0;i<n;i++) { int x,y; scanf("%d %d",&x,&y); orx[i]=x; ory[i]=y; kwadrat[i]=0; v.push_back(mp(x,y)); } sort(v.begin(),v.end()); if(ok()) { puts("TAK"); for(int vv=0;vv<n;vv++) { for(int i=0;i<n;i++) { if(v[i].f==orx[vv] && v[i].s==ory[vv]) { printf("%d ",kwadrat[i]); } } } puts(""); } else puts("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 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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | // to nie działa #include <cstdio> #include <cassert> #include <map> #include <vector> #include <algorithm> #include <list> #define MAKS 2100 #define ZADUZO 2000000001u #define f first #define s second #define mp make_pair using namespace std; typedef pair<int,int> para; typedef unsigned int uint; typedef long long int lld; int n; vector<para> v; int naj; int kwadrat[MAKS]; bool dasie(int ind, uint r) { if(r==0)return true; //printf("%d moze %u?\n",ind,r); for(int i=0;i<n;i++) { if(i==ind)continue; if(v[i].f>=v[ind].f && v[i].f<v[ind].f+r && v[i].s>=v[ind].s && v[i].s<v[ind].s+r)return false; if(kwadrat[i]==0)continue; if(((v[ind].f> v[i].f && v[ind].f < v[i].f+kwadrat[i]) || (v[ind].f+r> v[i].f && v[ind].f+r < v[i].f+kwadrat[i])) && ((v[ind].s> v[i].s && v[ind].s < v[i].s+kwadrat[i]) || (v[ind].s+r> v[i].s && v[ind].s+r < v[i].s+kwadrat[i]))) return false; } //puts("PEWKA"); return true; } bool ok() { if(n==1) { kwadrat[0]=1; return true; } for(int i=0;i<n;i++) { if(v[i].s<v[0].s)return false; } vector<int> pozostale; for(int i=0;i<n;i++)pozostale.push_back(i); while(pozostale.size()>1) { int ile=0; //printf("zostalo: %d\n",pozostale.size()); vector<int> akt; for(int i=0;i<pozostale.size();i++)akt.push_back(pozostale[i]); pozostale.clear(); for(int ind: akt) { uint pocz=0; uint kon=ZADUZO; while(pocz<kon) { uint sr=(pocz+kon+1)/2; if(dasie(ind,sr))pocz=sr; else kon=sr-1; } if(pocz==0)return false; else if(pocz==ZADUZO)pozostale.push_back(ind); else { kwadrat[ind]=pocz; //printf("%d dostaje %d\n",ind,pocz); ile++; } } //fprintf(stderr,"benc\n"); if(ile==0)break; } uint maksx=0; uint maksy=0; for(int i=0;i<n;i++) { uint kandx=v[i].f+kwadrat[i]; uint kandy=v[i].s+kwadrat[i]; if(kandx>maksx)maksx=kandx; if(kandy>maksy)maksy=kandy; } if(pozostale.size()>=1) { for(int ind: pozostale) { //printf("maksx: %u, maksy: %u\n",maksx,maksy); int kandr=maksx-v[ind].f; if(maksy-v[ind].s>kandr)kandr=maksy-v[ind].s; if(!dasie(ind,kandr))return false; kwadrat[ind]=kandr; //printf("%d dostaje ostatecznie %d\n",ind,kandr); if(v[ind].f+kandr>maksx)maksx=v[ind].f+kandr; if(v[ind].s+kandr>maksy)maksy=v[ind].s+kandr; } } // ostateczny sprawdzian lld pole1=lld(maksx-v[0].f)*lld(maksy-v[0].s); lld pole2=0; for(int i=0;i<n;i++) { pole2+=lld(kwadrat[i])*lld(kwadrat[i]); } //printf("%lld vs %lld\n",pole1,pole2); return pole1==pole2; } int orx[MAKS]; int ory[MAKS]; int main() { int t; scanf("%d",&t); while(t--) { scanf("%d",&n); v.clear(); naj=0; for(int i=0;i<n;i++) { int x,y; scanf("%d %d",&x,&y); orx[i]=x; ory[i]=y; kwadrat[i]=0; v.push_back(mp(x,y)); } sort(v.begin(),v.end()); if(ok()) { puts("TAK"); for(int vv=0;vv<n;vv++) { for(int i=0;i<n;i++) { if(v[i].f==orx[vv] && v[i].s==ory[vv]) { printf("%d ",kwadrat[i]); } } } puts(""); } else puts("NIE"); } } |