POJ 3168 排序+扫描
2016-10-30 14:47
176 查看
题意:
思路:
我们可以把每个矩形拆成四条线
与x轴平行的放在一起
与y轴平行的放在一起
排个序 判一判有没有交 有交 则说明不可扩张 统计一下 就可以了
处理的姿势很重要
姿势不对毁一生
//By SiriusRen #include <cstdio> #include <algorithm> using namespace std; #define N 55555 int n,x1,y1,x2,y2,cnt,vis ,ans,maxx; struct Edgex{int x,y1,y2,id;bool operator < (const Edgex &a)const{if(x!=a.x)return x<a.x;return y2<a.y2;}}edgex ; struct Edgey{int y,x1,x2,id;bool operator < (const Edgey &a)const{if(y!=a.y)return y<a.y;return x1<a.x1;}}edgey ; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d%d%d",&x1,&y1,&x2,&y2),vis[i]=1, edgex[++cnt].x=x1,edgex[cnt].y1=y2,edgex[cnt].y2=y1,edgex[cnt].id=i, edgey[cnt].y=y1,edgey[cnt].x1=x1,edgey[cnt].x2=x2,edgey[cnt].id=i, edgex[++cnt].x=x2,edgex[cnt].y1=y2,edgex[cnt].y2=y1,edgex[cnt].id=i, edgey[cnt].y=y2,edgey[cnt].x1=x1,edgey[cnt].x2=x2,edgey[cnt].id=i; sort(edgex+1,edgex+1+cnt),sort(edgey+1,edgey+1+cnt); for(int i=1,j=i;i<=cnt;i=j,maxx=edgex[i].y1){ while(edgex[i].x==edgex[j].x)j++; for(int k=i+1;k<j;k++){ if(edgex[k].y2<=maxx)vis[edgex[k].id]=vis[edgex[k-1].id]=0; maxx=max(maxx,edgex[k].y1); } } for(int i=1,j=i;i<=cnt;i=j,maxx=edgey[i].x2){ while(edgey[i].y==edgey[j].y)j++; for(int k=i+1;k<j;k++){ if(edgey[k].x1<=maxx)vis[edgey[k].id]=vis[edgey[k-1].id]=0; maxx=max(maxx,edgey[k].x2); } } for(int i=1;i<=n;i++)ans+=vis[i]; printf("%d\n",ans); }
相关文章推荐
- POJ 3168 排序+扫描
- poj 3168 Barn Expansion 排序
- poj_3168 平面扫描
- POJ 3168 Barn Expansion (几何基础)
- POJ 3168 Barn Expansion(几何啊 )
- [POJ 3168 Treats for the Cows]区间dp
- POJ 3168 Barn Expansion (几何+排序)
- poj 3168 Barn Expansion 几何yy
- POJ 3168 Barn Expansion (平面扫描)
- poj 3168 Barn Expansion 几何yy
- poj 3168 Barn Expansion
- poj 3168
- POJ 3168 Barn Expansion (平面扫描)
- POJ 3168 Barn Expansion 已翻译
- poj 3168 计算几何
- POJ2559 Largest Rectangle in a Histogram(DP)
- poj 2410 Simple Computers
- poj 1042(贪心)
- Poj 1328 贪心
- POJ 3345 Bribing FIPA 树形背包+字符串处理