codeforces 14 C. Four Segments
http://codeforces.com/problemset/problem/14/C 题意:给出四条边的坐标,问能否形成一个边与坐标轴平行的矩形。边可能退化成点。 思路:首先第一步,检查有没有边退化成点以及是否有不平行的边。
第二步,检查两个方向的边是否各有两条。。
第三步,将所有点的坐标排序。。然后看8个点是否会因为重合而变成4个.。
1/* ***********************************************
2Author :111qqz
3Created Time :2015年12月29日 星期二 16时28分28秒
4File Name :code/cf/problem/14C.cpp
5************************************************ */
6
7#include <cstdio>
8#include <cstring>
9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33int a,b,c,d;
34int l[10];
35int cnt;
36
37
38
39struct point
40{
41 int x,y;
42
43 bool operator <(point p)const
44 {
45 if (x<p.x) return true;
46 if (x==p.x&&y<p.y) return true;
47 return false;
48 }
49 bool ok (point p)
50 {
51 if (x!=p.x&&y!=p.y) return false; //不平行
52 if (x==p.x&&y==p.y) return false; //退化成一点
53 if (x==p.x) cnt++;
54 return true;
55 }
56
57 bool operator ==(point p)const
58 {
59 return x==p.x&&y==p.y;
60 }
61 bool operator !=(point p)const
62 {
63 if (x!=p.x||y!=p.y) return true;
64 return false;
65 }
66}p[10];
67int main()
68{
69 #ifndef ONLINE_JUDGE
70 freopen("code/in.txt","r",stdin);
71 #endif
72
73 bool ok=true;
74 cnt = 0 ;
75 for ( int i = 0 ; i < 4 ; i++)
76 {
77 cin>>p[i].x>>p[i].y>>p[i+4].x>>p[i+4].y;
78 if (!p[i].ok(p[i+4]))
79 {
80 ok = false;
81 }
82 }
83 if (!ok||cnt!=2)
84 {
85 puts("NO");
86
87 }
88 else
89 {
90 sort(p,p+8);
91 if (p[0]==p[1]&&p[2]==p[3]&&p[4]==p[5]&&p[6]==p[7]&&p[0]!=p[2]&&p[2]!=p[4]&&p[4]!=p[6]) //两两重合后保证四个点
92 {
93 puts("YES");
94 }
95 else
96 {
97 puts("NO");
98 }
99 }
100
101 #ifndef ONLINE_JUDGE
102 fclose(stdin);
103 #endif
104 return 0;
105}