zoukankan      html  css  js  c++  java
  • UVa221 Urban Elevations

    暴力枚举判断是否可见。

    注意特判几栋房子一起遮挡一栋房子的情况。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<queue>
     6 using namespace std;
     7 const int mxn=1010;
     8 struct building{
     9     int x,y,w,h;
    10     int id;
    11 }a[mxn],b[mxn];
    12 int cmp(const building c,const building d){
    13     return (c.x<d.x)||(c.x==d.x && c.y<d.y);
    14 }
    15 int n,m;
    16 bool check(int t){
    17     int pos=a[t].x;
    18     int cnt=0;
    19     for(int i=1;i<=n;i++){
    20         if(i==t)continue;
    21         if(a[i].y<a[t].y && a[i].x<=a[t].x && a[i].x+a[i].w>=a[t].x+a[t].w && a[i].h>=a[t].h)return false;
    22         if(a[i].y<a[t].y && a[i].h>=a[t].h && a[i].x<=pos && a[i].x+a[i].w>=pos)pos=max(pos,a[i].x+a[i].w);
    23     if(pos<a[t].x+a[t].w)return true;
    24     return false;
    25 }
    26 int ans[mxn],top=0;
    27 void solve(){
    28     for(int i=1;i<=n;i++)
    29         if(check(i))ans[++top]=a[i].id;
    30     return;
    31 }
    32 int main(){
    33     int i,j;
    34     int cas=0;
    35     while(scanf("%d",&n) && n){
    36         if(cas)printf("
    ");
    37         top=0;
    38         for(i=1;i<=n;i++){
    39             scanf("%d%d%d%*d%d",&a[i].x,&a[i].y,&a[i].w,&a[i].h);
    40             a[i].id=i;
    41         }
    42         sort(a+1,a+n+1,cmp);
    43         solve();
    44         printf("For map #%d, the visible buildings are numbered as follows:
    ",++cas);
    45         for(i=1;i<top;i++)printf("%d ",ans[i]);
    46         printf("%d",ans[top]);
    47         printf("
    ");
    48     }
    49     return 0;
    50 }
  • 相关阅读:
    画架构图
    做产品的方方面面
    Tomcat一个有意思的漏洞
    LinkedHashMap 作为一个 CacheMap
    Maven提高篇系列之五——处理依赖冲突
    javaweb获取项目路径的方法
    curl工具介绍和常用命令
    Spring事务管理(详解+实例)
    如何更好地使用Java 8的Optional
    input的type=file触发的相关事件
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/6389640.html
Copyright © 2011-2022 走看看