[枚举] HDU 2019 Multi-University Training Contest 8 - Calabash and Landlord
Posted railgun000
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[枚举] HDU 2019 Multi-University Training Contest 8 - Calabash and Landlord相关的知识,希望对你有一定的参考价值。
Calabash and Landlord
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 3228 Accepted Submission(s): 613
Problem Description
Calabash is the servant of a landlord. The landlord owns a piece of land, which can be regarded as an infinite 2D plane.
One day the landlord set up two orthogonal rectangular-shaped fences on his land. He asked Calabash a simple problem: how many nonempty connected components is my land divided into by these two fences, both finite and infinite? Calabash couldn‘t answer this simple question. Please help him!
Recall that a connected component is a maximal set of points not occupied by the fences, and every two points in the set are reachable without crossing the fence.
One day the landlord set up two orthogonal rectangular-shaped fences on his land. He asked Calabash a simple problem: how many nonempty connected components is my land divided into by these two fences, both finite and infinite? Calabash couldn‘t answer this simple question. Please help him!
Recall that a connected component is a maximal set of points not occupied by the fences, and every two points in the set are reachable without crossing the fence.
Input
The first line of input consists of a single integer T (1≤T, the number of test cases.
Each test case contains two lines, specifying the two rectangles. Each line contains four integers x1,y (0≤x1,y, where (x1,y are the Cartesian coordinates of two opposite vertices of the rectangular fence. The edges of the rectangles are parallel to the coordinate axes. The edges of the two rectangles may intersect, overlap, or even coincide.
Each test case contains two lines, specifying the two rectangles. Each line contains four integers x1,y (0≤x1,y, where (x1,y are the Cartesian coordinates of two opposite vertices of the rectangular fence. The edges of the rectangles are parallel to the coordinate axes. The edges of the two rectangles may intersect, overlap, or even coincide.
Output
For each test case, print the answer as an integer in one line.
Sample Input
3
0 0 1 1
2 2 3 4
1 0 3 2
0 1 2 3
0 0 1 1
0 0 1 1
Sample Output
3
4
2
题意:给你2个栅栏的坐标,栅栏会分割平面,问栅栏分割平面后有多少个连通块
思路:枚举所有情况,时间复杂度O(1),代码复杂度O(∞),一开始WA到自闭,就开始暴力模式,写的时候懵了,出现了一些难以发现的小错误,差点翻车,最后15分钟才改出来,
所有情况都在代码里了,可以看一下代码,这里就不细讲了
1 #include<bits/stdc++.h> 2 using namespace std; 3 int x_1[5],y_1[5],x_2[5],y_2[5]; 4 int main() 5 int t,a,b; 6 ios::sync_with_stdio(0); 7 cin>>t; 8 while(t--) 9 for(int i=0;i<=1;i++)cin>>x_1[i]>>y_1[i]>>x_2[i]>>y_2[i]; 10 a=0,b=1; 11 if(x_1[0]>x_1[1])a^=1,b^=1; 12 if(x_1[0]==x_1[1]) 13 if(x_2[b]>x_2[a]||y_2[b]>y_2[a]||y_1[b]<y_1[a])a^=1,b^=1; 14 15 if(x_1[a]==x_1[b]&&x_2[a]==x_2[b]&&y_1[a]==y_1[b]&&y_2[a]==y_2[b]) 16 cout<<2<<endl; 17 18 else 19 if(x_2[a]<=x_1[b]) 20 cout<<3<<endl; 21 22 else 23 if(y_2[a]<=y_1[b]||y_1[a]>=y_2[b]) 24 cout<<3<<endl; 25 26 else 27 if(x_1[a]==x_1[b]) ///l1 28 if(x_2[a]==x_2[b]) ///r1 29 if(y_1[a]==y_1[b]) ///d1 30 if(y_2[a]==y_2[b]) ///u1 31 cout<<2<<endl; 32 else 33 cout<<3<<endl; 34 35 else ///d0 36 if(y_2[a]==y_2[b]) ///u1 37 cout<<3<<endl; 38 else ///u0 39 cout<<4<<endl; 40 41 42 else if(x_2[b]>x_2[a]) ///l1 r0 43 if(y_1[a]==y_1[b]) ///d1 44 if(y_2[a]==y_2[b]||y_2[a]<y_2[b]) 45 cout<<3<<endl; 46 else if(y_2[a]>y_2[b]) 47 cout<<4<<endl; 48 49 else ///d0 50 if(y_1[a]<y_1[b]) 51 if(y_2[a]==y_2[b])cout<<4<<endl; 52 else if(y_2[a]>y_2[b]) cout<<5<<endl; 53 else cout<<4<<endl; 54 55 else 56 if(y_2[a]==y_2[b])cout<<3<<endl; 57 else if(y_2[a]>y_2[b]) cout<<4<<endl; 58 else cout<<3<<endl; 59 60 61 62 else 63 if(y_1[a]==y_1[b]) ///d1 64 if(y_2[a]==y_2[b]||y_2[a]>y_2[b]) 65 cout<<3<<endl; 66 else if(y_2[a]<y_2[b]) 67 cout<<4<<endl; 68 69 else ///d0 70 if(y_1[a]>y_1[b]) 71 if(y_2[a]==y_2[b])cout<<4<<endl; 72 else if(y_2[a]>y_2[b]) cout<<4<<endl; 73 else cout<<5<<endl; 74 75 else 76 if(y_2[a]==y_2[b])cout<<3<<endl; 77 else if(y_2[a]>y_2[b]) cout<<3<<endl; 78 else cout<<4<<endl; 79 80 81 82 83 else 84 if(x_2[a]==x_2[b]) ///l0 r1 85 if(y_1[a]==y_1[b]) 86 if(y_2[a]==y_2[b]) 87 cout<<3<<endl; 88 else if(y_2[a]>y_2[b])cout<<3<<endl; 89 else cout<<4<<endl; 90 91 else 92 if(y_1[a]<y_1[b]) 93 if(y_2[a]==y_2[b]||y_2[a]>y_2[b])cout<<3<<endl; 94 else cout<<4<<endl; 95 96 else 97 if(y_2[a]==y_2[b]||y_2[a]>y_2[b])cout<<4<<endl; 98 else cout<<5<<endl; 99 100 101 102 else 103 if(x_2[a]>x_2[b]) 104 if(y_1[a]==y_1[b]) 105 if(y_2[a]==y_2[b])cout<<4<<endl; 106 else if(y_2[a]>y_2[b])cout<<3<<endl; 107 else cout<<5<<endl; 108 109 else 110 if(y_1[a]<y_1[b]) 111 if(y_2[a]==y_2[b]||y_2[a]>y_2[b])cout<<3<<endl; 112 else cout<<4<<endl; 113 114 else 115 if(y_2[a]==y_2[b])cout<<5<<endl; 116 else if(y_2[a]>y_2[b])cout<<4<<endl; 117 else cout<<6<<endl; 118 119 120 121 else 122 if(y_1[a]==y_1[b]) 123 cout<<4<<endl; 124 125 else 126 if(y_1[a]<y_1[b]) 127 cout<<4<<endl; 128 129 else 130 if(y_2[a]==y_2[b]||y_2[a]>y_2[b])cout<<4<<endl; 131 else cout<<4<<endl; 132 133 134 135 136 137 138 139 140 141 142
以上是关于[枚举] HDU 2019 Multi-University Training Contest 8 - Calabash and Landlord的主要内容,如果未能解决你的问题,请参考以下文章
HDU校赛 | 2019 Multi-University Training Contest 3