Four Segments

Four Segments

Created by LXC on Wed Jul 5 21:50:50 2023

https://codeforces.com/problemset/problem/14/C

ranting: 1700

tag: brute force, constructive algorithms, geometry, implementation, math

problem

给出四条线段问能否组成矩形,且矩形的边平行于坐标轴。

solution

平行于x轴和y轴的边都是2条

此外每个点都需要经过两次

此外线段的长度不能为0

code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

#include <bits/stdc++.h>
#define SINGLE_INPUT
#define ll long long
#define ull unsigned long long
#define N 500005
#define MOD 998244353
using namespace std;


void sol() {
int r=0, c=0, ok = 1;
map<pair<int,int>, int> cnt;
for (int i=0; i<4; i++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2) r++;
if (y1 == y2) c++;
if (x1 == x2 && y1 == y2) ok = 0;
cnt[{x1,y1}]++;
cnt[{x2,y2}]++;
}
if (!ok ||r != 2 || c != 2) {
cout << "NO\n";
return ;
}
for (auto [i,j]:cnt) {
if (j != 2) {
cout << "NO\n";
return ;
}
}
cout << "YES\n";
}

int main() {
cout << setprecision(15) << fixed;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef SINGLE_INPUT
int t;
cin >> t;
while (t--) {
sol();
}
#else
sol();
#endif
return 0;
}