CF-14C - Four Segments(几何)
来源:互联网 发布:防范电信网络诈骗图片 编辑:程序博客网 时间:2024/05/17 10:04
Crawling in process...Crawling failedTime Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him.
Input
The input data contain four lines. Each of these lines contains four integers x1,y1,x2,y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points.
Output
Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO».
Sample Input
1 1 6 11 0 6 06 0 6 11 1 1 0
YES
0 0 0 32 0 0 02 2 2 00 2 2 2
NO
思路:简单几何,先判断是个四边形,判断有条边与X轴平行,再判断每个角是90度,就是矩形了。
判断有点小技巧,具体看代码。
失误点:比赛的时候粗心,看落了个条件,要求要有边和x轴平行。结果╮(╯▽╰)╭
#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<map>using namespace std;const double pi=3.1415926;class node{public: int x,y,xx,yy; int z;}s[77];int num[44];map<int,int>mp;int main(){ int a,b,c,d; while(cin>>a>>b>>c>>d) { memset(num,0,sizeof(num)); bool ans=0; for(int i=0;i<4;i++) { if(a==c&&b==d)ans=1; s[i].x=a;s[i].y=b;s[i].xx=c;s[i].yy=d;///交换点生成一遍好判断 s[i+4].x=c;s[i+4].y=d;s[i+4].xx=a;s[i+4].yy=b; if(i!=3)cin>>a>>b>>c>>d; } bool flag=1; for(int i=0;i<4;i++) for(int j=0;j<8;j++) { if(i==j)continue; if(s[i].x==s[j].x&&s[i].y==s[j].y) num[i]++;///判断是个四边形,那有且仅有两个点一样 if(s[i].y==s[i].yy)flag=0;///判断有条边是x轴平行就行了 } if(flag)ans=1; for(int i=0;i<4;i++) if(num[i]!=1)ans=1; for(int i=0;i<4;i++) for(int j=0;j<8;j++) { if(i==j)continue; double x,y,xx,yy,z,zz; if(s[i].x==s[j].x&&s[i].y==s[j].y)///判断角都是90度 {///向量知识,(x,y)*(xx,yy)=(长度乘积)cos degree; x=s[i].x-s[i].xx; y=s[i].y-s[i].yy; xx=s[i].x-s[j].xx; yy=s[i].y-s[j].yy; z=x*xx+y*yy; zz=sqrt(x*x+y*y)*sqrt(xx*xx+yy*yy); z=z/zz; z=acos(z)/pi*180; /// cout<<z<<endl; if(abs(z-90.0)>0.0001)ans=1; } } if(ans)cout<<"NO\n"; else cout<<"YES\n"; }}
- CF-14C - Four Segments(几何)
- CodeForces 14C Four Segments
- CodeForces 14C Four Segments (简单题)
- Codeforces-846C:Four Segments
- Codeforces 846 C Four Segments(前缀和+枚举)
- [POJ3304]Segments(计算几何)
- Codeforces 846C Four Segments【思维+预处理+前缀和枚举】
- CF#284 (Div. 2) C.(几何规律)
- poj 3304 Segments(计算几何)
- poj 3304 Segments(计算几何:叉积)
- poj 3304 Segments(计算几何)
- POJ 3304 Segments(计算几何)
- POJ-3304 Segments(计算几何)
- poj3304 Segments(计算几何+直线相交)
- POJ 3304 Segments(计算几何)
- CF 408C Triangle 勾股数+简单几何
- 【计算几何】 poj3304 Segments
- Segments(计算几何基础)
- 《Python 第二章》列表和元组
- 订票助手
- bigbluebutton 安装日志
- Gridview 增加多个空行。
- macro definitions (#define, #undef)
- CF-14C - Four Segments(几何)
- 如何在 Web 浏览器中启用 Java?
- 五块美金+二小时,你要怎样赚到钱?
- ehcache 搭建
- ios debug 输出
- Asp.net Gridview合并单元格
- 用c++和python写GUI程序(python嵌入方式)
- objective-c sqlite3 最原始的使用
- UML-对象图