[arc076e]Connected?
来源:互联网 发布:战地2武器数据修改 编辑:程序博客网 时间:2024/06/14 04:15
题目大意
一个矩形,n个数字填入了其中,每个数字出现两次。
对于一对相同的数字,使用一条极端细的可弯曲的线连起来(不允许出矩形)。
是否存在一种连线方案使得任意两条线不相交。
做法
只有两个数字都在矩形边界上,连线会分割矩形。
不妨先不连这些数字对,最后再来连。
于是你可以发现只要这些数字对能合法就能合法。
按顺时针做个栈贪心就好了。
#include<cstdio>#include<algorithm>#define fo(i,a,b) for(i=a;i<=b;i++)using namespace std;const int maxn=200000+10;struct dong{ int id,x,y;} p[maxn],p1,p2;struct suan{ dong x,y;} a[maxn];int sta[maxn];int i,j,k,l,t,n,m,x,y,r,c,tot,top;bool is(dong x){ return x.x==0||x.y==0||x.x==r||x.y==c;}int sum(dong x){ if(x.x==0) return 2*r+c+c-x.y; if(x.y==0) return x.x+x.y; if(x.x==r) return r+x.y; if(x.y==c) return r+c+r-x.x;}bool cmp(dong a,dong b){ return sum(a)<sum(b);}int main(){ scanf("%d%d%d",&r,&c,&n); fo(i,1,n){ scanf("%d%d",&x,&y); p1=(dong){i,x,y}; scanf("%d%d",&x,&y); p2=(dong){i,x,y}; a[i]=(suan){p1,p2}; if (is(p1)&&is(p2)){ p[++tot]=p1; p[++tot]=p2; } } sort(p+1,p+tot+1,cmp); fo(i,1,tot){ if (top&&sta[top]==p[i].id) top--; else sta[++top]=p[i].id; } if (top) printf("NO\n");else printf("YES\n");}
阅读全文
0 0
- [arc076e]Connected?
- Connected Systems
- Connected Graph
- People Get Connected
- poj 1737 Connected Graph
- Doubly connected edge list
- poj 1737 Connected Graph
- Nodally 3-connected graph
- Doubly connected edge list
- Connected Components Labeling
- windbg Debuggee not connected
- Connected component labeling
- HDOJ4635 strongly connected
- HDOJ 4635: Strongly connected
- HDU4635 Strongly connected
- hdu 4635Strongly connected
- Socket是否connected?
- Metasploit Database not connected
- UE4在VR模式下如何使手柄震动
- Hadoop使用 MapReduce排序思路、全局排序
- 关于img 403 forbidden的一些思考
- iOS app打包签名原理
- unix pthread_create 函数使用时需要注意的一个地方
- [arc076e]Connected?
- long Long数据比较的错误
- Python编程:从入门到实践的动手试一试答案(第十一章)
- Ubuntu安装tensorflow报错:tensorflow-xx.whl not a supported wheel on this platform
- 使用NDK编译FFmpeg到Android下使用
- Dubbo分布式服务框架入门(附工程)
- 既存既取 文件服务器优化
- 中序线索化二叉树
- struct