题目链接:http://codeforces.com/problemset/problem/14/C
题意:给出四条线段的端点,若这四条线段能组成一个平行于坐标轴的矩形,且面积为正,输出YES,反之NO。
分析:讨论,一共四个点,两条平行x,两条平行y,每条线段长度必须重复不小于2次。
代码:
#include<cstdio> #include<cmath> #include<cstring> #include<queue> #include<stack> #include<cstdlib> #include<iomanip> #include<string> #include<vector> #include<map> #include<string> #include<iostream> #include<algorithm> using namespace std; #define INF 0x3f3f3f3f typedef long long ll; #define Max(a,b) (a>b)?a:b #define lowbit(x) x&(-x) int main() { map<int,map<int,int> >mp; map<int,int>mp1; int x[4],y[4],len=0,flag=1,x1[4],y1[4],xx=0,yy=0; for(int i=0; i<4; i++) { scanf("%d%d",&x[i],&y[i]); scanf("%d%d",&x1[i],&y1[i]); mp[x[i]][y[i]]++; mp[x1[i]][y1[i]]++; if((x1[i]==x[i])&&(y1[i]!=y[i])) yy++; else if((x1[i]!=x[i])&&(y1[i]==y[i])) xx++; else flag=0; len=abs(x1[i]-x[i]+y1[i]-y[i]); mp1[len]++; } if(xx!=yy) flag=0; for(int i=0; i<4; i++) { if(mp[x[i]][y[i]]!=2||mp[x1[i]][y1[i]]!=2) flag=0; len=abs(x1[i]-x[i]+y1[i]-y[i]); if(mp1[len]<2) flag=0; } if(flag) puts("YES"); else puts("NO"); }
时间: 2024-10-08 20:04:32