CodeForces 14C Four Segments (简单题)

题目类型  简单题

题目意思
给你4条线段 问是否能组成一个边要和坐标轴平行的矩形 (给出的线段可能是一个点)

解题方法
对于每个点 看是否只有一个点和它是相同的
如果是 看输入的 4 条边是否 是 其中两条和 x 轴平行 另两条和 y 轴平行
满足以上两个条件即可

参考代码 - 有疑问的地方在下方留言 看到会尽快回复的
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>

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;
}


你可能感兴趣的:(codeforces,简单题)