#include <stdio.h> #define max(a, b) (((a) >= (b)) ? (a) : (b)) #define min(a, b) (((a) <= (b)) ? (a) : (b)) struct Segment { int x_; int y_; }; int inside(const struct Segment* a, const struct Segment* b) { return (((a->x_ <= b->x_) && (b->y_ <= a->y_)) ? 1 : 0); } void copy_segment(struct Segment* a, const struct Segment* b) { a->x_ = b->x_; a->y_ = b->y_; } void update_segment(struct Segment* a, const struct Segment* b) { a->x_ = min(a->x_, b->x_); a->y_ = max(a->y_, b->y_); } void get_segment(struct Segment* a) { scanf("%d%d", &a->x_, &a->y_); } struct Mirror { struct Segment w_; struct Segment h_; }; int is_major_mirror(const struct Mirror* x, const struct Mirror* y) { return (((inside(&x->w_, &y->w_) == 1) && (inside(&x->h_, &y->h_) == 1)) ? 1 : 0); } void copy_mirror(struct Mirror* x, const struct Mirror* y) { copy_segment(&x->w_, &y->w_); copy_segment(&x->h_, &y->h_); } void update_mirror(struct Mirror* x, const struct Mirror* y) { update_segment(&x->w_, &y->w_); update_segment(&x->h_, &y->h_); } void get_mirror(struct Mirror* x) { get_segment(&x->w_); get_segment(&x->h_); } int main(void) { int t, n; struct Mirror mirror, major_mirror; int found; scanf("%d", &t); while (t--) { scanf("%d", &n); found = 1; get_mirror(&major_mirror); n -= 1; while (n--) { get_mirror(&mirror); if (is_major_mirror(&mirror, &major_mirror) == 1) { found = 1; copy_mirror(&major_mirror, &mirror); } else if (is_major_mirror(&major_mirror, &mirror) == 0) { found = 0; update_mirror(&major_mirror, &mirror); } } if (found == 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 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 | #include <stdio.h> #define max(a, b) (((a) >= (b)) ? (a) : (b)) #define min(a, b) (((a) <= (b)) ? (a) : (b)) struct Segment { int x_; int y_; }; int inside(const struct Segment* a, const struct Segment* b) { return (((a->x_ <= b->x_) && (b->y_ <= a->y_)) ? 1 : 0); } void copy_segment(struct Segment* a, const struct Segment* b) { a->x_ = b->x_; a->y_ = b->y_; } void update_segment(struct Segment* a, const struct Segment* b) { a->x_ = min(a->x_, b->x_); a->y_ = max(a->y_, b->y_); } void get_segment(struct Segment* a) { scanf("%d%d", &a->x_, &a->y_); } struct Mirror { struct Segment w_; struct Segment h_; }; int is_major_mirror(const struct Mirror* x, const struct Mirror* y) { return (((inside(&x->w_, &y->w_) == 1) && (inside(&x->h_, &y->h_) == 1)) ? 1 : 0); } void copy_mirror(struct Mirror* x, const struct Mirror* y) { copy_segment(&x->w_, &y->w_); copy_segment(&x->h_, &y->h_); } void update_mirror(struct Mirror* x, const struct Mirror* y) { update_segment(&x->w_, &y->w_); update_segment(&x->h_, &y->h_); } void get_mirror(struct Mirror* x) { get_segment(&x->w_); get_segment(&x->h_); } int main(void) { int t, n; struct Mirror mirror, major_mirror; int found; scanf("%d", &t); while (t--) { scanf("%d", &n); found = 1; get_mirror(&major_mirror); n -= 1; while (n--) { get_mirror(&mirror); if (is_major_mirror(&mirror, &major_mirror) == 1) { found = 1; copy_mirror(&major_mirror, &mirror); } else if (is_major_mirror(&major_mirror, &mirror) == 0) { found = 0; update_mirror(&major_mirror, &mirror); } } if (found == 1) { printf("TAK\n"); } else { printf("NIE\n"); } } return 0; } |