0%

天梯赛练习集 L3-006 迎风一刀斩

迎风一刀斩

看到这题的时候一脸懵逼。。。后来才发现原来旋转角度只有90度、180度、或270度。。。不过还是查了一下题解。。。

其实只有四种情况,只要会画就差不多会写了。

这里写图片描述

解释一下代码。。。
check()可以通过引用返回横向的长(X)短(x)边,纵向的长(Y)短(y)边,以及平行坐标轴的边数(strt)。
penta()本来是用来判断五边形和三角形的,后来发现前三个写起来都一样就都合在一起了。
quaqua()用来判断两个四边形能不能拼成矩形,其中两个矩形是一种特殊情况 ,如果一个的边长是(A, B),另一个是(X, Y),只要A/B中的一个和X/Y中的一个相等就可以了。
其他一般的情况都是通过图中的相等关系判断的。

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
PII a[6],b[6];

inline void input(PII a[],int &n)
{
scanf("%d",&n);
for (int i=0;i<n;i++) {
int x,y;
scanf("%d%d",&x,&y);
a[i]=PII(x,y);
}
}

inline void check(PII a[],int n,int &X,int &x,int &Y,int &y,int &strt)
{
X=x=Y=y=strt=0;
for (int i=0;i<n;i++) {
if (a[i].first==a[(i+1)%n].first) {
strt++;
int tmp=abs(a[i].second-a[(i+1)%n].second);
if (tmp>Y) y=Y,Y=tmp;
else y=tmp;
} else if (a[i].second==a[(i+1)%n].second) {
strt++;
int tmp=abs(a[i].first-a[(i+1)%n].first);
if (tmp>X) x=X,X=tmp;
else x=tmp;
}
}
}

inline bool penta(int n,int m)
{
int x,X,y,Y,strt;
check(b,m,X,x,Y,y,strt);
if (strt!=m-1) return false;
int A=Y-y,B=X-x;
check(a,n,X,x,Y,y,strt);
if (strt!=n-1) return false;
return (X==A&&Y==B)||(X==B&&Y==A);
}

bool quaqua()
{
int x,X,y,Y,strt;
check(b,4,X,x,Y,y,strt);
if (strt<3) return false;
if (strt==4) {
int A=X,B=Y;
check(a,4,X,x,Y,y,strt);
if (strt!=4) return false;
return A==X||A==Y||B==X||B==Y;
}
int height,A,B;
if (y==0) {
height=Y;A=X;B=x;
} else {
height=X;A=Y;B=y;
}
check(a,4,X,x,Y,y,strt);
if (strt<3) return false;
if (y==0) {
return height==Y&&x+A==X+B;
} else {
return height==X&&y+A==Y+B;
}
}

int main()
{
int T,n,m;
scanf("%d",&T);
while (T--) {
input(a,n);
input(b,m);
if (n>m) {
swap(n,m);
swap(a,b);
}
bool f=false;
if (n==4&&m==4) f=quaqua();
else f=penta(n,m);
puts(f?"YES":"NO");
}
return 0;
}

独立写的代码一发过,很开心。

咖啡,亦我所需也