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. TCPCopy 线上流量复制工具

    TCPCopy是一种重放TCP流的工具,使用真实环境来测试互联网服务器上的应用程序. 一.描述: 虽然真实的实时流量对于Internet服务器应用程序的测试很重要,但是由于生产环境中的情况很负责,测试 ...

  2. tomcat&servlet初记

    tomcat&servlet初记 1. web相关概念 2. web服务器软件的学习:tomcat 3. servlet入门学习 web相关概念 1,软件架构 1,cs架构:客户端/服务器端 ...

  3. lnmp 一键安装包(nginx) 运行laravel项目显示该网页无法正常运行

    vi /usr/local/nginx/conf/fastcgi.conf 注释掉 PHP_ADMIN_VALUE #fastcgi_param PHP_ADMIN_VALUE "open_ ...

  4. 正式学习MVC 05

    1.剃须刀模板razor的使用 1)混编 循环语法 @model List<MVCStudy.Models.Student> @{ ViewBag.Title = "List&q ...

  5. React Native 在 Airbnb(译文)

    在Android,iOS,Web和跨平台框架的横向对比中,React Native本身是一个相对较新且快速开发移动的平台.两年后,我们可以肯定地说React Native在很多方面都是革命性的.这是移 ...

  6. 基础JavaScript练习(三)总结

    任务目的 实践JavaScript数组.字符串相关操作 任务描述 基于任务四进行升级 将新元素输入框从input改为textarea 允许一次批量输入多个内容,格式可以为数字.中文.英文等,可以通过用 ...

  7. Wireshark网络分析就这么简单——读书笔记

    前言 什么是wireshark? wireshark可能是世界上最好的开源网络分析器,能在多个平台上(Linux.Mac和Windows)抓取和分析网络包 wireshark分析常见的协议,可以在学习 ...

  8. 01 极简Linux操作系统发展历史

    Unix操作系统的诞生 1965 年之前的时候,电脑并不像现在一样普遍,它可不是一般人能碰的起的,除非是军事或者学院的研究机构,而且当时大型主机至多能提供30台终端(30个键盘.显示器),连接一台电脑 ...

  9. 浅谈Spring框架

    一.Spring简介 Spring 是一个开源框架,是为了解决企业应用程序开发复杂性而创建的.框架的主要优势之一就是其分层架构, 分层架构允许您选择使用哪一个组件,同时为 J2EE 应用程序开发提供集 ...

  10. JS实战(京东秒杀)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...