Terry's Blog

Terry's Blog

我好菜啊

题解 【CF14C Four Segments】

posted on 2021-10-15 13:47:02 | under 题解 |

题解 【CF14C Four Segments】

Solution

先在大脑里画一个矩形。
然后就有了对于解决这道题目的几个关键性质。

  • 1:对边平行,邻边垂直
  • 2:四条线段首尾拼接而成

好,接下来专门解决一些细节。
题目中已经保证了输入数据与坐标轴平行,所以说可以不用判断这个问题,当然,判断一下更好。
在保证上述条件的同时,第二个要做的事情就是判断是否由四条线段首尾拼接而成,这个只需要判断线段的每一个端点是否出现两次即可。
最后判断一下这 4 条线段是否出现重合现象。
这题就做完了,觉得评橙就差不多了。

Code

#include <bits/stdc++.h>
using namespace std;

#define gc getchar
inline int read() {
    int c = gc(), t = 1, n = 0;
    while(isspace(c)) { c = gc(); }
    if(c == '-') { t = -1, c = gc(); }
    while(isdigit(c)) { n = n * 10 + c - '0', c = gc(); }
    return n * t;
}
#undef gc

map <pair <int,int>,int>mp;

int a,b,c,d;
int x,y,cnt;

int main() {
    for(int i = 1;i <= 4;i++) {
        a = read(); b = read();
        c = read(); d = read();
        mp[make_pair(a,b)]++; mp[make_pair(c,d)]++; //先存下所有的点,这样子就可以方便判重
        if(a != c && b != d) puts("NO"),exit(0);    //如果说输入不符合题目要求,肯定是不行的
        x += (a == c); y += (b == d);   //搞出来这是和什么轴平行的,易得有且只有两条线段会与同一轴平行
        cnt += (mp[make_pair(a,b)] == 2);   //判断有几个点重合,易得有且只有四个点会重合
        cnt += (mp[make_pair(c,d)] == 2);   //同上
    }
    if(x != 2 || y != 2 || cnt != 4) puts("NO"),exit(0);    //如果不满足以上条件,就输出不符合
    puts("YES");
    return 0;
}