#include<bits/stdc++.h>
using namespace std;
bool pox(pair<int, int> a, pair<int, int> b)
{
return a.first < b.first;
}
bool poy(pair<int, int> a, pair<int, int> b)
{
return a.second < b.second;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t, n, x, y, xmax, ymax, ymin, xmin;
vector<pair<int, int>> wek;
cin >> t;
for(int i = 0; i < t; i++){
cin >> n;
for(int j = 0; j < n; j++){
cin >> x >> y;
wek.push_back(make_pair(x,y));
}
if(n == 1){ //just one point
cout << "TAK 7" << '\n';
continue;
}
vector<pair<int, int>> wekx = wek;
sort(wekx.begin(), wekx.end(), pox);
vector<pair<int, int>> weky = wek;
sort(weky.begin(), weky.end(), poy);
xmax = wekx[n-1].first;
xmin = wekx[0].first;
ymax = weky[n-1].second;
ymin = weky[0].second;
if(xmax == xmin){ // all points on one line(vertical)
int d = weky[1].second - weky[0].second;
bool czy = 1;
for(int j = 1; j+1 < n; j++){
if(weky[j+1].second - weky[j].second != d){
czy = 0;
break;
}
}
if(czy){
cout << "TAK ";
for(int j = 0; j < n; j++)
cout << d << " ";
cout << '\n';
continue;
}
else{
cout << "NIE" << '\n';
continue;
}
}
if(ymax == ymin){ //all points in one line(horizontal)
int d = wekx[1].first - wekx[0].first;
bool czy = 1;
for(int j = 1; j+1 < n; j++){
cout << wekx[j+1].first - wekx[j].first << endl;
if(wekx[j+1].first - wekx[j].first != d){
czy = 0;
break;
}
}
if(czy){
cout << "TAK ";
for(int j = 0; j < n; j++)
cout << d << " ";
cout << '\n';
continue;
}
else{
cout << "NIE" << '\n';
continue;
}
}
cout << "NIE" << '\n';
wek.clear();
}
return 0;
}
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 | #include<bits/stdc++.h> using namespace std; bool pox(pair<int, int> a, pair<int, int> b) { return a.first < b.first; } bool poy(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t, n, x, y, xmax, ymax, ymin, xmin; vector<pair<int, int>> wek; cin >> t; for(int i = 0; i < t; i++){ cin >> n; for(int j = 0; j < n; j++){ cin >> x >> y; wek.push_back(make_pair(x,y)); } if(n == 1){ //just one point cout << "TAK 7" << '\n'; continue; } vector<pair<int, int>> wekx = wek; sort(wekx.begin(), wekx.end(), pox); vector<pair<int, int>> weky = wek; sort(weky.begin(), weky.end(), poy); xmax = wekx[n-1].first; xmin = wekx[0].first; ymax = weky[n-1].second; ymin = weky[0].second; if(xmax == xmin){ // all points on one line(vertical) int d = weky[1].second - weky[0].second; bool czy = 1; for(int j = 1; j+1 < n; j++){ if(weky[j+1].second - weky[j].second != d){ czy = 0; break; } } if(czy){ cout << "TAK "; for(int j = 0; j < n; j++) cout << d << " "; cout << '\n'; continue; } else{ cout << "NIE" << '\n'; continue; } } if(ymax == ymin){ //all points in one line(horizontal) int d = wekx[1].first - wekx[0].first; bool czy = 1; for(int j = 1; j+1 < n; j++){ cout << wekx[j+1].first - wekx[j].first << endl; if(wekx[j+1].first - wekx[j].first != d){ czy = 0; break; } } if(czy){ cout << "TAK "; for(int j = 0; j < n; j++) cout << d << " "; cout << '\n'; continue; } else{ cout << "NIE" << '\n'; continue; } } cout << "NIE" << '\n'; wek.clear(); } return 0; } |
English