1. 程式人生 > >bzoj3715 [PA2014]Lustra

bzoj3715 [PA2014]Lustra

需要 reg 一個 pen 公司 log spa 前綴 getchar

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

正解:模擬。

簡單模擬,記錄前綴後綴最小最大值即可。

 1 #include <bits/stdc++.h>
 2 #define
il inline 3 #define RG register 4 #define ll long long 5 #define inf (1<<30) 6 #define N (100010) 7 8 using namespace std; 9 10 int w1[N],h1[N],w2[N],h2[N],pw1[N],ph1[N],pw2[N],ph2[N],sw1[N],sh1[N],sw2[N],sh2[N],n; 11 12 il int gi(){ 13 RG int x=0,q=1; RG char ch=getchar(); 14
while ((ch<0 || ch>9) && ch!=-) ch=getchar(); 15 if (ch==-) q=-1,ch=getchar(); 16 while (ch>=0 && ch<=9) x=x*10+ch-48,ch=getchar(); 17 return q*x; 18 } 19 20 il void work(){ 21 n=gi(),sw1[n+1]=sh1[n+1]=inf,sw2[n+1]=sh2[n+1]=0; 22 for (RG int i=1;i<=n;++i){ 23 w1[i]=gi(),w2[i]=gi(),h1[i]=gi(),h2[i]=gi(); 24 pw1[i]=min(pw1[i-1],w1[i]),ph1[i]=min(ph1[i-1],h1[i]); 25 pw2[i]=max(pw2[i-1],w2[i]),ph2[i]=max(ph2[i-1],h2[i]); 26 } 27 for (RG int i=n;i;--i){ 28 sw1[i]=min(sw1[i+1],w1[i]),sh1[i]=min(sh1[i+1],h1[i]); 29 sw2[i]=max(sw2[i+1],w2[i]),sh2[i]=max(sh2[i+1],h2[i]); 30 } 31 for (RG int i=1,mnw,mnh,mxw,mxh;i<=n;++i){ 32 mnw=min(pw1[i-1],sw1[i+1]),mnh=min(ph1[i-1],sh1[i+1]); 33 mxw=max(pw2[i-1],sw2[i+1]),mxh=max(ph2[i-1],sh2[i+1]); 34 if (w1[i]<=mnw && h1[i]<=mnh && w2[i]>=mxw && h2[i]>=mxh){ puts("TAK"); return; } 35 } 36 puts("NIE"); return; 37 } 38 39 int main(){ 40 #ifndef ONLINE_JUDGE 41 freopen("Lustra.in","r",stdin); 42 freopen("Lustra.out","w",stdout); 43 #endif 44 pw1[0]=ph1[0]=inf; 45 RG int T=gi(); while (T--) work(); return 0; 46 }

bzoj3715 [PA2014]Lustra