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.

 
Input
The first line of input consists of a single integer T (1≤T≤10000), the number of test cases.

Each test case contains two lines, specifying the two rectangles. Each line contains four integers x1,y1,x2,y2 (0≤x1,y1,x2,y2≤109,x1<x2,y1<y2), where (x1,y1),(x2,y2)
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分钟才改出来,

所有情况都在代码里了,可以看一下代码,这里就不细讲了

 #include<bits/stdc++.h>
using namespace std;
int x_1[],y_1[],x_2[],y_2[];
int main(){
int t,a,b;
ios::sync_with_stdio();
cin>>t;
while(t--){
for(int i=;i<=;i++)cin>>x_1[i]>>y_1[i]>>x_2[i]>>y_2[i];
a=,b=;
if(x_1[]>x_1[])a^=,b^=;
if(x_1[]==x_1[]){
if(x_2[b]>x_2[a]||y_2[b]>y_2[a]||y_1[b]<y_1[a])a^=,b^=;
}
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]){
cout<<<<endl;
}
else{
if(x_2[a]<=x_1[b]){
cout<<<<endl;
}
else{
if(y_2[a]<=y_1[b]||y_1[a]>=y_2[b]){
cout<<<<endl;
}
else{
if(x_1[a]==x_1[b]){ ///l1
if(x_2[a]==x_2[b]){ ///r1
if(y_1[a]==y_1[b]){ ///d1
if(y_2[a]==y_2[b]) ///u1
cout<<<<endl;
else
cout<<<<endl;
}
else{ ///d0
if(y_2[a]==y_2[b]) ///u1
cout<<<<endl;
else ///u0
cout<<<<endl;
}
}
else if(x_2[b]>x_2[a]){ ///l1 r0
if(y_1[a]==y_1[b]){ ///d1
if(y_2[a]==y_2[b]||y_2[a]<y_2[b])
cout<<<<endl;
else if(y_2[a]>y_2[b])
cout<<<<endl;
}
else{ ///d0
if(y_1[a]<y_1[b]){
if(y_2[a]==y_2[b])cout<<<<endl;
else if(y_2[a]>y_2[b]) cout<<<<endl;
else cout<<<<endl;
}
else{
if(y_2[a]==y_2[b])cout<<<<endl;
else if(y_2[a]>y_2[b]) cout<<<<endl;
else cout<<<<endl;
}
}
}
else{
if(y_1[a]==y_1[b]){ ///d1
if(y_2[a]==y_2[b]||y_2[a]>y_2[b])
cout<<<<endl;
else if(y_2[a]<y_2[b])
cout<<<<endl;
}
else{ ///d0
if(y_1[a]>y_1[b]){
if(y_2[a]==y_2[b])cout<<<<endl;
else if(y_2[a]>y_2[b]) cout<<<<endl;
else cout<<<<endl;
}
else{
if(y_2[a]==y_2[b])cout<<<<endl;
else if(y_2[a]>y_2[b]) cout<<<<endl;
else cout<<<<endl;
}
}
}
}
else{
if(x_2[a]==x_2[b]){ ///l0 r1
if(y_1[a]==y_1[b]){
if(y_2[a]==y_2[b])
cout<<<<endl;
else if(y_2[a]>y_2[b])cout<<<<endl;
else cout<<<<endl;
}
else{
if(y_1[a]<y_1[b]){
if(y_2[a]==y_2[b]||y_2[a]>y_2[b])cout<<<<endl;
else cout<<<<endl;
}
else{
if(y_2[a]==y_2[b]||y_2[a]>y_2[b])cout<<<<endl;
else cout<<<<endl;
}
}
}
else{
if(x_2[a]>x_2[b]){
if(y_1[a]==y_1[b]){
if(y_2[a]==y_2[b])cout<<<<endl;
else if(y_2[a]>y_2[b])cout<<<<endl;
else cout<<<<endl;
}
else{
if(y_1[a]<y_1[b]){
if(y_2[a]==y_2[b]||y_2[a]>y_2[b])cout<<<<endl;
else cout<<<<endl;
}
else{
if(y_2[a]==y_2[b])cout<<<<endl;
else if(y_2[a]>y_2[b])cout<<<<endl;
else cout<<<<endl;
}
}
}
else{
if(y_1[a]==y_1[b]){
cout<<<<endl;
}
else{
if(y_1[a]<y_1[b]){
cout<<<<endl;
}
else{
if(y_2[a]==y_2[b]||y_2[a]>y_2[b])cout<<<<endl;
else cout<<<<endl;
}
}
}
}
}
}
}
}
} }

[枚举] HDU 2019 Multi-University Training Contest 8 - Calabash and Landlord的更多相关文章

  1. hdu 4864 Task---2014 Multi-University Training Contest 1

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 Task Time Limit: 4000/2000 MS (Java/Others)    M ...

  2. hdu 4937 2014 Multi-University Training Contest 7 1003

    Lucky Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) T ...

  3. hdu 4946 2014 Multi-University Training Contest 8

    Area of Mushroom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  4. HDU 6395 2018 Multi-University Training Contest 7 (快速幂+分块)

    原题地址 Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  5. hdu 4941 2014 Multi-University Training Contest 7 1007

    Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  6. hdu 4939 2014 Multi-University Training Contest 7 1005

    Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  7. HDU - 6304(2018 Multi-University Training Contest 1) Chiaki Sequence Revisited(数学+思维)

    http://acm.hdu.edu.cn/showproblem.php?pid=6304 题意 给出一个数列的定义,a[1]=a[2]=1,a[n]=a[n-a[n-1]]+a[n-1-a[n-2 ...

  8. hdu 5755 2016 Multi-University Training Contest 3 Gambler Bo 高斯消元模3同余方程

    http://acm.hdu.edu.cn/showproblem.php?pid=5755 题意:一个N*M的矩阵,改变一个格子,本身+2,四周+1.同时mod 3;问操作多少次,矩阵变为全0.输出 ...

  9. hdu 5738 2016 Multi-University Training Contest 2 Eureka 计数问题(组合数学+STL)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5738 题意:从n(n <= 1000)个点(有重点)中选出m(m > 1)个点(选出的点只 ...

随机推荐

  1. 方兴未艾的云计算:SoCC 2015大会

    ACM 云计算研讨会(ACM Symposium on Cloud Computing, 以下简称SoCC)是由SIGMOD(Special Interest Group on Management ...

  2. ubuntu16.04问题 · 最初的梦想

    ubuntu 包管理器命令 1 $ sudo synaptic 安装主题 1 $ sudo apt-get install unity-tweak-tool 下载主题 https://www.sysg ...

  3. AI未来如何应对人类的欺骗?

    人工智能正以可预见.不可预见的种种形式无孔不入地涉足社会的各个层面,这既让人兴奋,也让人不安.我们能够预测到这样的情绪反应,但我们真的能够预测到人工智能所涉及的相关风险吗? 假若现在是2022年,你乘 ...

  4. React Native Build Apk

    1 React Native安卓项目打包APK 1.1 产生签名的key 先通过keytool生成key 1 keytool -genkey -v -keystore demo-release-key ...

  5. Git的安装与TortoiseGit的安装和汉化

    下载Git 进入https://git-scm.com/downloads 可以看到如下界面 因为我是windows系统,选择windows即可. 有的朋友因为网络慢的一些原因不能很快下载下来,可以进 ...

  6. FPGA小白学习之路(1) System Verilog的概念以及与verilog的对比(转)

    转自CSDN:http://blog.csdn.net/gtatcs/article/details/8970489 SystemVerilog语言简介 SystemVerilog是一种硬件描述和验证 ...

  7. Qt_QChart的使用记录(小白)

    主要是记录柱状图的数值显示,散点图的点坐标显示(防止后续忘记,把文件都贴出来,方便复查) 资源库: WarehouseInputOrOutput.pro QT += core gui QT += ch ...

  8. Yuchuan_Linux_C编程之九目录操作相关函数

    一.整体大纲 二.相关函数 1. getcwd 函数作用:获取当前目录 头文件 #include <unistd.h> 函数原型 char *getcwd(char *buf, size_ ...

  9. jQuery上传文件按钮美化

    效果图如下: 思路: 1:打开文件设置为透明,外面包一层标签,给标签设置颜色背景,给人点击浏览其实是点击打开文件的错觉.(给外标签相对定位,打开文件标签绝对定位). 2:点击浏览后,选择了文件,就把文 ...

  10. vue+webpack怎么分环境进行打包

    这里说下,webpack打包里面涉及到的东西,不止webpack,还有node的知识, node的全局变量process,process.env用于返回用户环境信息对象,因为是node的全局变量,所以 ...