#include <cstdio> int main() { int t; scanf("%d", &t); while (t--) { int n,w1,w2,h1,h2; int current[4][2]; //current[(w1,w2,h1,h2)][(wartość, wiersz z wejścia)] scanf("%d", &n); scanf("%d %d %d %d", &w1, &w2, &h1, &h2); current[0][0] = w1; current[1][0] = w2; current[2][0] = h1; current[3][0] = h2; current[0][1] = current[1][1] = current[2][1] = current[3][1] = 0; for (int i=1; i<n; ++i) { scanf("%d %d %d %d", &w1, &w2, &h1, &h2); if (w1 < current[0][0] || current[1][0] < w2 || h1 < current[2][0] || current[3][0] < h2) { //rozszerza to co najmniej jeden wymiar, więc trzeba zaktualizować wszystkie if (w1 <= current[0][0]) { current[0][0] = w1; current[0][1] = i; } if (current[1][0] <= w2) { current[1][0] = w2; current[1][1] = i; } if (h1 <= current[2][0]) { current[2][0] = h1; current[2][1] = i; } if (current[3][0] <= h2) { current[3][0] = h2; current[3][1] = i; } } else { if (w1 == current[0][0] && current[1][0] == w2 && h1 == current[2][0] && current[3][0] == h2) //nie rozszerza żadnego wymiaru, ale przynajmniej wyrównuje wszystkie dotychczasowe current[0][1] = current[1][1] = current[2][1] = current[3][1] = i; } } if (current[0][1] == current[1][1] && current[1][1] == current[2][1] && current[2][1] == current[3][1]) 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 | #include <cstdio> int main() { int t; scanf("%d", &t); while (t--) { int n,w1,w2,h1,h2; int current[4][2]; //current[(w1,w2,h1,h2)][(wartość, wiersz z wejścia)] scanf("%d", &n); scanf("%d %d %d %d", &w1, &w2, &h1, &h2); current[0][0] = w1; current[1][0] = w2; current[2][0] = h1; current[3][0] = h2; current[0][1] = current[1][1] = current[2][1] = current[3][1] = 0; for (int i=1; i<n; ++i) { scanf("%d %d %d %d", &w1, &w2, &h1, &h2); if (w1 < current[0][0] || current[1][0] < w2 || h1 < current[2][0] || current[3][0] < h2) { //rozszerza to co najmniej jeden wymiar, więc trzeba zaktualizować wszystkie if (w1 <= current[0][0]) { current[0][0] = w1; current[0][1] = i; } if (current[1][0] <= w2) { current[1][0] = w2; current[1][1] = i; } if (h1 <= current[2][0]) { current[2][0] = h1; current[2][1] = i; } if (current[3][0] <= h2) { current[3][0] = h2; current[3][1] = i; } } else { if (w1 == current[0][0] && current[1][0] == w2 && h1 == current[2][0] && current[3][0] == h2) //nie rozszerza żadnego wymiaru, ale przynajmniej wyrównuje wszystkie dotychczasowe current[0][1] = current[1][1] = current[2][1] = current[3][1] = i; } } if (current[0][1] == current[1][1] && current[1][1] == current[2][1] && current[2][1] == current[3][1]) printf("TAK\n"); else printf("NIE\n"); } return 0; } |