codeforces 14 C. Four Segments
http://codeforces.com/problemset/problem/14/C 题意:给出四条边的坐标,问能否形成一个边与坐标轴平行的矩形。边可能退化成点。 思路:首先第一步,检查有没有边退化成点以及是否有不平行的边。
第二步,检查两个方向的边是否各有两条。。
第三步,将所有点的坐标排序。。然后看8个点是否会因为重合而变成4个.。
/* ***********************************************
Author :111qqz
Created Time :2015年12月29日 星期二 16时28分28秒
File Name :code/cf/problem/14C.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6int a,b,c,d;
7int l[10];
8int cnt;
1struct point
2{
3 int x,y;
1 bool operator <(point p)const
2 {
3 if (x<p.x) return true;
4 if (x==p.x&&y<p.y) return true;
5 return false;
6 }
7 bool ok (point p)
8 {
9 if (x!=p.x&&y!=p.y) return false; //不平行
10 if (x==p.x&&y==p.y) return false; //退化成一点
11 if (x==p.x) cnt++;
12 return true;
13 }
1 bool operator ==(point p)const
2 {
3 return x==p.x&&y==p.y;
4 }
5 bool operator !=(point p)const
6 {
7 if (x!=p.x||y!=p.y) return true;
8 return false;
9 }
10}p[10];
11int main()
12{
13 #ifndef ONLINE_JUDGE
14 freopen("code/in.txt","r",stdin);
15 #endif
1 bool ok=true;
2 cnt = 0 ;
3 for ( int i = 0 ; i < 4 ; i++)
4 {
5 cin>>p[i].x>>p[i].y>>p[i+4].x>>p[i+4].y;
6 if (!p[i].ok(p[i+4]))
7 {
8 ok = false;
9 }
10 }
11 if (!ok||cnt!=2)
12 {
13 puts("NO");
1 }
2 else
3 {
4 sort(p,p+8);
5 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]) //两两重合后保证四个点
6 {
7 puts("YES");
8 }
9 else
10 {
11 puts("NO");
12 }
13 }
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}