Niestety, nie byliśmy w stanie w pełni poprawnie wyświetlić tego pliku, ponieważ nie jest zakodowany w UTF-8.
Możesz pobrać ten plik i spróbować otworzyć go samodzielnie.
#include <cstdio> #include <vector> #include <algorithm> using namespace std; struct Rect { int xstart_min, ystart_min, xstart_max, ystart_max; int xfinish_min, yfinish_min, xfinish_max, yfinish_max; int xmin_range_min, xmin_range_max; int height; }; void read_data(vector<Rect> &rects, bool &incorrect_data) { int N = (int)rects.size(); for(int i=0; i<N; i++) { scanf("%d %d %d %d", &rects[i].xstart_min, &rects[i].ystart_min, &rects[i].xstart_max, &rects[i].ystart_max); if(rects[i].xstart_min > rects[i].xstart_max) swap(rects[i].xstart_min, rects[i].xstart_max); if(rects[i].ystart_min > rects[i].ystart_max) swap(rects[i].ystart_min, rects[i].ystart_max); } for(int i=0; i<N; i++) { scanf("%d %d %d %d", &rects[i].xfinish_min, &rects[i].yfinish_min, &rects[i].xfinish_max, &rects[i].yfinish_max); if(rects[i].xfinish_min > rects[i].xfinish_max) swap(rects[i].xfinish_min, rects[i].xfinish_max); if(rects[i].yfinish_min > rects[i].yfinish_max) swap(rects[i].yfinish_min, rects[i].yfinish_max); if(rects[i].yfinish_max - rects[i].yfinish_min != rects[i].ystart_max - rects[i].ystart_min || rects[i].xfinish_max - rects[i].xfinish_min != rects[i].xstart_max - rects[i].xstart_min) { incorrect_data = true; } rects[i].xmin_range_min = rects[i].xstart_min; rects[i].xmin_range_max = rects[i].xfinish_min; if(rects[i].xmin_range_min > rects[i].xmin_range_max) swap(rects[i].xmin_range_min, rects[i].xmin_range_max); rects[i].height = rects[i].yfinish_max - rects[i].yfinish_min; } } int signum(int x) { if(x>0) return +1; if(x<0) return -1; return 0; } bool main_check(const vector<Rect> &rects, int FIELD_HEIGHT) { int N = (int)rects.size(); for(int i=0; i<N; i++) for(int j=i+1; j<N; j++) if(rects[i].height + rects[j].height > FIELD_HEIGHT) { int xmin = max(rects[i].xmin_range_min, rects[j].xmin_range_min); int xmax = min(rects[i].xmin_range_max, rects[j].xmin_range_max); if(xmax >= xmin) { // intersection exists if(signum(rects[i].xfinish_min - rects[i].xstart_min) != signum(rects[j].xfinish_min - rects[j].xstart_min)) return false; // ���� � ����� ��������� if(xmin==rects[i].xmin_range_min && xmax==rects[i].xmin_range_max) return false; // i-� �������� ��������� j-���� if(xmin==rects[j].xmin_range_min && xmax==rects[j].xmin_range_max) return false; // j-� �������� ��������� i-���� } }; return true; } int main(int argc, char* argv[]) { #ifdef _DEBUG freopen("PAR.dat", "rt", stdin); #endif int TEST_NUM; scanf("%d", &TEST_NUM); for(int the_test = 0; the_test < TEST_NUM; the_test++) { int N; int FIELD_HEIGHT; scanf("%d %d", &N, &FIELD_HEIGHT); vector<Rect> rects(N); bool is_incorrect_data = false; read_data(rects, is_incorrect_data); if(is_incorrect_data) { printf("NIE\n"); continue; } if(main_check(rects, FIELD_HEIGHT)) printf("TAK\n"); else printf("NIE\n"); } 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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | #include <cstdio> #include <vector> #include <algorithm> using namespace std; struct Rect { int xstart_min, ystart_min, xstart_max, ystart_max; int xfinish_min, yfinish_min, xfinish_max, yfinish_max; int xmin_range_min, xmin_range_max; int height; }; void read_data(vector<Rect> &rects, bool &incorrect_data) { int N = (int)rects.size(); for(int i=0; i<N; i++) { scanf("%d %d %d %d", &rects[i].xstart_min, &rects[i].ystart_min, &rects[i].xstart_max, &rects[i].ystart_max); if(rects[i].xstart_min > rects[i].xstart_max) swap(rects[i].xstart_min, rects[i].xstart_max); if(rects[i].ystart_min > rects[i].ystart_max) swap(rects[i].ystart_min, rects[i].ystart_max); } for(int i=0; i<N; i++) { scanf("%d %d %d %d", &rects[i].xfinish_min, &rects[i].yfinish_min, &rects[i].xfinish_max, &rects[i].yfinish_max); if(rects[i].xfinish_min > rects[i].xfinish_max) swap(rects[i].xfinish_min, rects[i].xfinish_max); if(rects[i].yfinish_min > rects[i].yfinish_max) swap(rects[i].yfinish_min, rects[i].yfinish_max); if(rects[i].yfinish_max - rects[i].yfinish_min != rects[i].ystart_max - rects[i].ystart_min || rects[i].xfinish_max - rects[i].xfinish_min != rects[i].xstart_max - rects[i].xstart_min) { incorrect_data = true; } rects[i].xmin_range_min = rects[i].xstart_min; rects[i].xmin_range_max = rects[i].xfinish_min; if(rects[i].xmin_range_min > rects[i].xmin_range_max) swap(rects[i].xmin_range_min, rects[i].xmin_range_max); rects[i].height = rects[i].yfinish_max - rects[i].yfinish_min; } } int signum(int x) { if(x>0) return +1; if(x<0) return -1; return 0; } bool main_check(const vector<Rect> &rects, int FIELD_HEIGHT) { int N = (int)rects.size(); for(int i=0; i<N; i++) for(int j=i+1; j<N; j++) if(rects[i].height + rects[j].height > FIELD_HEIGHT) { int xmin = max(rects[i].xmin_range_min, rects[j].xmin_range_min); int xmax = min(rects[i].xmin_range_max, rects[j].xmin_range_max); if(xmax >= xmin) { // intersection exists if(signum(rects[i].xfinish_min - rects[i].xstart_min) != signum(rects[j].xfinish_min - rects[j].xstart_min)) return false; // ���� � ����� ��������� if(xmin==rects[i].xmin_range_min && xmax==rects[i].xmin_range_max) return false; // i-� �������� ��������� j-���� if(xmin==rects[j].xmin_range_min && xmax==rects[j].xmin_range_max) return false; // j-� �������� ��������� i-���� } }; return true; } int main(int argc, char* argv[]) { #ifdef _DEBUG freopen("PAR.dat", "rt", stdin); #endif int TEST_NUM; scanf("%d", &TEST_NUM); for(int the_test = 0; the_test < TEST_NUM; the_test++) { int N; int FIELD_HEIGHT; scanf("%d %d", &N, &FIELD_HEIGHT); vector<Rect> rects(N); bool is_incorrect_data = false; read_data(rects, is_incorrect_data); if(is_incorrect_data) { printf("NIE\n"); continue; } if(main_check(rects, FIELD_HEIGHT)) printf("TAK\n"); else printf("NIE\n"); } return 0; } |