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
#include <stdio.h>
#include <vector>

//#define FROM_FILE

#ifdef FROM_FILE
#include <iostream>
#include <fstream>
#endif

using namespace std;

class Rect
{
public:
	int wMin;
	int wMax;
	int hMin;
	int hMax;

	bool operator == ( const Rect & r ) const
	{
		return wMin == r.wMin && wMax == r.wMax && hMin == r.hMin && hMax == r.hMax;
	}
};
typedef vector< Rect > RectArray;

int main(int argc, char **argv)
{
#ifdef FROM_FILE
    ifstream fin( "sample_mirrors.txt" );

    if ( !fin.is_open( ) )
    {
    	printf( "No file!\n" );
    	return 0;
    }
#endif

    int tc_quantity;

#ifdef FROM_FILE
    fin >> tc_quantity;
#else
    scanf( "%d", &tc_quantity );
#endif

    for ( int tc=0; tc<tc_quantity; ++tc )
    {
    	int rectQ;
#ifdef FROM_FILE
    	fin >> rectQ;
#else
    	scanf( "%d", &rectQ );
#endif
    	RectArray rects;

    	Rect maxR;
    	maxR.wMin = 1e9 +1;
    	maxR.wMax = 0;
    	maxR.hMin = 1e9 + 1;
    	maxR.hMax = 0;

    	Rect tempR;
    	for ( int i=0; i<rectQ; ++i )
    	{
#ifdef FROM_FILE
    		fin >> tempR.wMin >> tempR.wMax >> tempR.hMin >> tempR.hMax;
#else
    		scanf( "%d %d %d %d", &tempR.wMin, &tempR.wMax, &tempR.hMin, &tempR.hMax );
#endif
    		rects.push_back( tempR );

    		if ( maxR.wMin > tempR.wMin )
    			maxR.wMin = tempR.wMin;
    		if ( maxR.wMax < tempR.wMax )
    			maxR.wMax = tempR.wMax;
    		if ( maxR.hMin > tempR.hMin )
    			maxR.hMin = tempR.hMin;
    		if ( maxR.hMax < tempR.hMax )
    			maxR.hMax = tempR.hMax;
    	}

    	bool found = false;
    	for ( int i=0; i<rectQ; ++i )
    	{
    		if ( rects[i] == maxR )
    		{
    			found = true;
    			break;
    		}
    	}
    	if ( found )
    		printf( "TAK\n" );
    	else
    		printf( "NIE\n" );

    }
    return 0;
}