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
#include "stdio.h"
#include <algorithm>
using namespace std;

int main(int argc, char* argv[])
{
	unsigned int t(0);
	unsigned int p(0);
	scanf( "%d", &t );

	for (unsigned int i=0; i<t; i++)
	{
		scanf( "%d", &p );

		unsigned long **tab = new unsigned long*[p];
		for (unsigned int j=0; j<p; j++)
		{
			tab[j] = new unsigned long[4];
			for (unsigned int k=0; k<4; k++)
			{
				scanf( "%ul", &tab[j][k] );
			}
		}

		bool test = false;
		for (unsigned int j=0; j<p; j++)
		{
			test = true;
			for (unsigned int l=1; l<p; l++)
			{
				if (!( tab[0][0] <= tab[l][0] && tab[0][1] >= tab[l][1] && tab[0][2] <= tab[l][2] && tab[0][3] >= tab[l][3] ))
				{
					test &= false;
					break;
				}
			}
			if ( test )
			{
				printf("TAK\n");
				break;
			}

			if ( j < p-1 )
			for (unsigned int k=0; k<4; k++)
			{
				swap( tab[0][k], tab[j+1][k] );		
			}
		}
		if (!test)
			printf("NIE\n");

		for (unsigned int j=0; j<p; j++)
		{
			delete [] tab[j];
		}
		delete [] tab;
	}
	return 0;
}