题目链接:https://codeforces.com/contest/14/problem/C
给出4条线段判断是否构成矩形。
判断是否平行于坐标轴,是否平行x轴y轴的各2条,重合点个数是否为4个即可。
#include <iostream>
#include <map>
using namespace std;
int main()
{
bool flag=true;
map<pair<int,int>,int> _hash;
int cnt=0;
int cntx=0,cnty=0;
for(int i=0;i<4;i++)
{
int x1,x2,y1,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1!=x2) cnty++;
else if(y1!=y2) cntx++;
else flag=false;
_hash[{x1,y1}]++;
if(_hash[{x1,y1}]==2) cnt++;
_hash[{x2,y2}]++;
if(_hash[{x2,y2}]==2) cnt++;
}
if(cnt!=4 || cntx!=2 || cnty!=2) flag=false;
if(flag) puts("YES");
else puts("NO");
return 0;
}