版权声明:欢迎转载!拒绝抄袭. https://blog.csdn.net/qq_36257146/article/details/88165693
#include <iostream>
#include <bits/stdc++.h>
#define maxn 100+5
using namespace std;
int n;
struct Node
{
double x,y,w,d,h;
int id;
Node(double x,double y,double w,double d,double h,int id):x(x),y(y),w(w),d(d),h(h),id(id){};
Node(){}
bool operator < (const Node & a) const{
return (x<a.x || (x==a.x&&y<a.y) );
}
};
Node nodes[maxn];
double x[2*maxn];//放置x坐标的数组
bool cover(int i,double l)
{
return nodes[i].x<=l && nodes[i].x + nodes[i].w >=l;
}
bool visible(int i,double l)
{
if(cover(i,l))
{
for(int j = 0;j<n;j++)
{
if(nodes[j].y<nodes[i].y && cover(j,l) && nodes[j].h>=nodes[i].h) return false;
}
return true;
}
return false;
}
int main()
{
int kase = 0;
while(cin>>n&&n)
{
for(int i = 0;i<n;i++)
{
cin>>nodes[i].x>>nodes[i].y>>nodes[i].w>>nodes[i].d>>nodes[i].h;
x[2*i] = nodes[i].x; x[2*i+1] = nodes[i].x+nodes[i].w;
nodes[i].id = i+1;
}
sort(nodes,nodes+n);
sort(x,x+2*n);
int m = unique(x,x+2*n)-x;
if(kase++) cout<<endl;
cout<<"For map #"<<kase<<", the visible buildings are numbered as follows:\n"<<nodes[0].id;
for(int i = 1;i<n;i++)
{
for(int j = 0;j<m-1;j++)
{
if(visible(i, (x[j]+x[j+1])/2 ))
{
cout<<" "<<nodes[i].id;
break;
}
}
}
cout<<endl;
}
return 0;
}