codeforces 14c 计算几何

题意:给你四条线段,问能否构成平行于坐标轴的矩形

题解:先确保每个点只有一个点和它重合,然后再保证四条边横平竖直

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
 
const int MAXN = 5000 + 10;
 
struct Node {
  int x, y;
};
 
int main() {
  Node p[8];
  while(scanf("%d %d %d %d", &p[0]. x, &p[0]. y, &p[1]. x, &p[1]. y) != EOF) {
    for( int i = 2; i < 8; i ++ ) {
      scanf("%d %d", &p[i]. x, &p[i]. y);
    }
    bool flag = true;
    for( int i = 0; i < 8; i ++ ) {
      int cnt = 0;
      for( int j = 0; j < 8; j ++ ) {
        if(p[i]. x == p[j]. x && p[i]. y == p[j]. y) cnt ++;
      }
      if(cnt != 2) {
        flag = false;
        break;
      }
    }
    if(flag == false) {
      printf("NO\n");
      continue;
    }
    int tx = 0, ty = 0;
    for( int i = 0; i < 4; i ++ ) {
      if(p[i * 2]. x == p[i * 2 + 1]. x && p[i * 2]. y != p[i * 2 + 1]. y) tx ++;
      if(p[i * 2]. x != p[i * 2 + 1]. x && p[i * 2]. y == p[i * 2 + 1]. y) ty ++;
    }
    if(!(tx == 2 && ty == 2)) flag = false;
    if(flag) printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_38759433/article/details/86559674