zoukankan      html  css  js  c++  java
  • bzoj3715 [PA2014]Lustra

    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 }
  • 相关阅读:
    java 之 模板模式(大话设计模式)
    java 之 原型模式(大话设计模式)
    java 之 工厂模式(大话设计模式)
    java 之 代理模式(大话设计模式)
    java 之 装饰模式(大话设计模式)
    java 之 策略模式(大话设计模式)
    java 之 简单工厂模式(大话设计模式)
    SVNKit完成前台Tree列表
    eclipse导出jar(含依赖)三步走
    简化SSM搭建详细分析配置
  • 原文地址:https://www.cnblogs.com/wfj2048/p/7668067.html
Copyright © 2011-2022 走看看