您的位置:首页 > 其它

bzoj3715 [PA2014]Lustra

2017-10-14 18:22 357 查看

Description

Byteasar公司专门外包生产带有镜子的衣柜。
刚刚举行的招标会上,有n个工厂参加竞标。所有镜子都是长方形的,每个工厂能够制造的镜子都有其各自的最大、最小宽度和最大、最小高度。镜子不可以旋转。
如果存在某家工厂满足这样的条件:其他所有工厂能够制造的镜子,它都能够制造。那么这家工厂显然会胜出。若不存在,评判工作将会遇到麻烦。Byteasar想知道,是否存在某家工厂符合上述条件。

Input

第一行有一个整数t(1<=t<=10),表示测试数据数量。
对于每一组测试数据,第一行有一个整数n(2<=n<=100000)。接下来n行,每行有四个整数w1,w2,h1,h2(1<=w1<=w2<=10^9,1<=h1<=h2<=10^9),表示这家工厂能够制造的镜子的宽度w、高度h需要满足w1<=w<=w2,h1<=h<=h2。

Output

输出共有t行,每行为TAK(是)或NIE(否),表示是否存在某家工厂符合条件。

Sample Input

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

Sample Output

TAK

NIE

TAK

正解:模拟。

简单模拟,记录前缀后缀最小最大值即可。

#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define inf (1<<30)
#define N (100010)

using namespace std;

int w1
,h1
,w2
,h2
,pw1
,ph1
,pw2
,ph2
,sw1
,sh1
,sw2
,sh2
,n;

il int gi(){
RG int x=0,q=1; RG char ch=getchar();
while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
if (ch=='-') q=-1,ch=getchar();
while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar();
return q*x;
}

il void work(){
n=gi(),sw1[n+1]=sh1[n+1]=inf,sw2[n+1]=sh2[n+1]=0;
for (RG int i=1;i<=n;++i){
w1[i]=gi(),w2[i]=gi(),h1[i]=gi(),h2[i]=gi();
pw1[i]=min(pw1[i-1],w1[i]),ph1[i]=min(ph1[i-1],h1[i]);
pw2[i]=max(pw2[i-1],w2[i]),ph2[i]=max(ph2[i-1],h2[i]);
}
for (RG int i=n;i;--i){
sw1[i]=min(sw1[i+1],w1[i]),sh1[i]=min(sh1[i+1],h1[i]);
sw2[i]=max(sw2[i+1],w2[i]),sh2[i]=max(sh2[i+1],h2[i]);
}
for (RG int i=1,mnw,mnh,mxw,mxh;i<=n;++i){
mnw=min(pw1[i-1],sw1[i+1]),mnh=min(ph1[i-1],sh1[i+1]);
mxw=max(pw2[i-1],sw2[i+1]),mxh=max(ph2[i-1],sh2[i+1]);
if (w1[i]<=mnw && h1[i]<=mnh && w2[i]>=mxw && h2[i]>=mxh){ puts("TAK"); return; }
}
puts("NIE"); return;
}

int main(){
#ifndef ONLINE_JUDGE
freopen("Lustra.in","r",stdin);
freopen("Lustra.out","w",stdout);
#endif
pw1[0]=ph1[0]=inf;
RG int T=gi(); while (T--) work(); return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: