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
169
170
171
172
173
174
175
176
#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>
//#include "lus.h"

using namespace std;

struct Point{
	int32_t x,y;
	Point();
	Point(int32_t x, int32_t y);
};

bool operator==(const Point & first, const Point & second);

class WindowOffer{
	public:
		WindowOffer();
		WindowOffer(Point bottomLeftCorner,Point upperRightCorner);
		void setBottomLeftCorner(Point bottomLeftCorner);
		Point getBottomLeftCorner() const;
		void setUpperRightCorner(Point upperRightCorner);
		Point getUpperRightCorner() const;

		bool contains(const WindowOffer & other) const;

		int64_t getArea() const;

	protected:
		Point bottomLeftCorner;
		Point upperRightCorner;
};

bool operator==(const WindowOffer & first, const WindowOffer & second);

std::istream & operator>>(std::istream & stream, WindowOffer & offer);

bool isMajorant(const WindowOffer & majorant, std::vector<WindowOffer*> & offers);

WindowOffer getPossibleMajorant(std::vector<WindowOffer*> offers);


void readOffers(vector<WindowOffer*> & offers){
	size_t n;
	cin>>n;
	offers.reserve(n);
	for(size_t i = 0; i<n; ++i){
		WindowOffer * offer = new WindowOffer;
		cin>>(*offer);
		offers.push_back(offer);
	}
}

void removeOffers(vector<WindowOffer*> & offers){
	size_t n = offers.size();
	for(size_t i=0; i<n; ++i){
		delete offers[i];
	}
	offers.clear();
}

void runTest(){
	vector<WindowOffer*> offers;
	readOffers(offers);

	WindowOffer majorant = getPossibleMajorant(offers);

	if(isMajorant(majorant,offers)){
		cout<<"TAK\n";
	}
	else cout<<"NIE\n";

	removeOffers(offers);
}


int main(){
	ios_base::sync_with_stdio(0);
	int16_t t;
	cin>>t;
	while(t--){
		runTest();
	}
	return 0;
}


Point::Point() : x(0),y(0){

}

Point::Point(int32_t x, int32_t y) : x(x),y(y) {

}

bool operator==(const Point & first, const Point & second){
	return (first.x==second.x && first.y==second.y);
}


WindowOffer::WindowOffer(){
};

WindowOffer::WindowOffer(Point bottomLeftCorner,Point upperRightCorner) 
	: bottomLeftCorner(bottomLeftCorner), upperRightCorner(upperRightCorner){
};

void WindowOffer::setBottomLeftCorner(Point bottomLeftCorner){
	this->bottomLeftCorner=bottomLeftCorner;
};

Point WindowOffer::getBottomLeftCorner() const{
	return bottomLeftCorner;
};

void WindowOffer::setUpperRightCorner(Point upperRightCorner){
	this->upperRightCorner=upperRightCorner;
};

Point WindowOffer::getUpperRightCorner() const{
	return upperRightCorner;
};

bool WindowOffer::contains(const WindowOffer & other) const{
	if(this->bottomLeftCorner.x <= other.bottomLeftCorner.x && this->upperRightCorner.x >= other.upperRightCorner.x){
		if(this->bottomLeftCorner.y <= other.bottomLeftCorner.y && this->upperRightCorner.y >= other.upperRightCorner.y){
			return true;
		}
		else return false;
	}
	else return false;
}

int64_t WindowOffer::getArea() const{
	return static_cast<int64_t>((upperRightCorner.x-bottomLeftCorner.x+1)) * static_cast<int64_t>((upperRightCorner.y-bottomLeftCorner.y+1));
}

bool operator==(const WindowOffer & first, const WindowOffer & second){
	return (first.getBottomLeftCorner()==second.getBottomLeftCorner() && first.getUpperRightCorner()==second.getUpperRightCorner());
}

istream & operator>>(istream & stream, WindowOffer & offer){
	Point bottomLeft;
	Point upperRight;
	stream>>bottomLeft.x>>upperRight.x>>bottomLeft.y>>upperRight.y;
	offer.setBottomLeftCorner(bottomLeft);
	offer.setUpperRightCorner(upperRight);
	return stream;
}

bool isMajorant(const WindowOffer & majorant,vector<WindowOffer*> & offers){
	for(auto offer : offers){
		if(!majorant.contains(*offer))return false;
	}
	return true;
}

WindowOffer getPossibleMajorant(std::vector<WindowOffer*> offers){
	WindowOffer *majorant;
	/*sort(offers.begin(),offers.end(),
		[](WindowOffer* o1, WindowOffer *o2)->bool
		{
			return (o1->getArea()>o2->getArea());
		});
	majorant = offers[0];
	*/

	majorant = *max_element(offers.begin(),offers.end(),
		[](WindowOffer* o1, WindowOffer *o2)->bool
		{
			return (o1->getArea()<o2->getArea());
		});

	return *majorant;
}