描述 Description
Byteasar 公司专门外包生产带有镜子的衣柜。
刚刚举行的招标会上,有 n 个工厂参加竞标。所有镜子都是长方形的,每个工厂能够制造的镜子都有其各自的最大、最小宽度和最大、最小高度。镜子不可以旋转。
如果存在某家工厂满足这样的条件:其他所有工厂能够制造的镜子,它都能够制造。那么这家工厂显然会胜出。若不存在,评判工作将会遇到麻烦。Byteasar 想知道,是否存在某家工厂符合上述条件。
输入格式 InputFormat
第一行有一个整数 t(1<=t<=10),表示测试数据数量。
对于每一组测试数据,第一行有一个整数 n(2<=n<=100000)。接下来 n 行,每行有四个整数 w1,w2,h1,h2(1<=w1<=w2<=109,1<=h1<=h2<=109),表示这家工厂能够制造的镜子的宽度 w、高度 h 需要满足 w1<=w<=w2,h1<=h<=h2。
输出格式 OutputFormat
输出共有 t 行,每行为 TAK(是) 或 NIE(否),表示是否存在某家工厂符合条件。
样例输入 SampleInput
3
3
2 3 3 5
1 4 2 6
1 3 4 6
3
1 5 1 3
2 4 1 3
3 4 2 5
4
1 2 1 10
1 2 3 8
2 2 7 10
1 2 1 10
样例输出 SampleOutput
TAK
NIE
TAK
代码 Code
模拟。
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int inf=0x7fffffff/27.11;
int i,j,t,n,m,l,r,k,z,y,x;
inline void read(int &x)
{
x=0;char ch=getchar();
while (ch<'0' || ch>'9') ch=getchar();
while (ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
}
int a[100005],b[100005],c[100005],d[100005];
int h1,h2,w1,w2,id;
int main()
{
read(t);
while (t--)
{
read(n);
for (i=1;i<=n;i++) read(a[i]),read(b[i]),read(c[i]),read(d[i]);
w1=*min_element(a+1,a+n+1);
w2=*max_element(b+1,b+n+1);
h1=*min_element(c+1,c+n+1);
h2=*max_element(d+1,d+n+1);
id=0;
for (i=1;i<=n;i++) if (w1==a[i] && w2==b[i] && h1==c[i] && h2==d[i]) id=1;
if (id) printf("TAK\n");
else printf("NIE\n");
}
return 0;
}