codeforce 14C
来源:互联网 发布:js class隐藏元素 编辑:程序博客网 时间:2024/05/17 08:22
http://vjudge.net/contest/view.action?cid=47975#problem/C
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
注意:给定的四条线段不一定可以围成一个四边形。
答题思路:统计出现的八个点的个数,每个点重复两次。在四边形中每一个点和其相邻的两个点的一个横坐标以纵坐标相同。
#include <stdio.h>struct point{ int x,y;} p[10];int main(){ int i,j,t,f; int a[10]; while(~scanf("%d%d%d%d",&p[0].x,&p[0].y,&p[1].x,&p[1].y)) { int cnt=0; f=1; if(p[0].x==p[1].x) cnt+=1; else if(p[0].y==p[1].y) cnt+=10; else f=0; a[0]=a[1]=0; for(i=2; i<8; i+=2) { scanf("%d%d%d%d",&p[i].x,&p[i].y,&p[i+1].x,&p[i+1].y); if(p[i].x==p[i+1].x) cnt+=1; else if(p[i].y==p[i+1].y) cnt+=10; else f=0; a[i]=a[i+1]=0; } if(cnt!=22) f=0; for(i=0; i<8; i++) { for(j=0; j<8; j++) { if(p[i].x==p[j].x&&p[i].y==p[j].y) a[i]++; } } for(i=0; i<8; i++) if(a[i]!=2) f=0; if(f) printf("YES\n"); else printf("NO\n"); } return 0;}
- codeforce 14C
- Codeforce # C. Average Score
- CodeForce 279C
- codeforce 237 C D
- Codeforce C. Barcode
- Codeforce 57C Array
- Codeforce 240C Practice
- Codeforce 332C
- codeforce 370C
- codeforce 400 C
- codeforce 6C
- codeforce 12C map
- codeforce 18C
- codeforce 447C
- codeforce 20140808 C. Boredom
- codeforce 492 C D
- (288C)codeforce
- (385C)codeforce
- 线程笔记
- 数据结构课程设计题目十二_计算机学院学生会的打印机(优先队列)
- struts2配置加实现
- 令人敬畏的泰格伍兹
- leetcode:Palindrome Partitioning
- codeforce 14C
- postgrepsql数据库安装配置使用
- Linux内核设计基础(十)之内核开发与总结
- 基于粒子滤波器的目标跟踪算法及实现
- 关于权限管理的demo
- FIQ和IRQ区别
- c++面试题之 找出字符串中第一个只出现一次的字符
- Spring3学习
- 跳跃表-原理及Java实现