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. 杂记:OSX 安装openssl

    因为工作中要用到openssl中提供的MD5.SHA等摘要算法,通过brew install openssl安装的openssl在C文件中找不到相应的头文件.按照网上的教程各种修改之后还是找不到相应的 ...

  2. 美团新零售招聘-高级测试开发(20k-50k/月)

    内推邮箱:liuxinguang@meituan.com 地点:北京 职位级别:p2-2以上级别 15.5薪

  3. [iOS 开发] WebViewJavascriptBridge 从原理到实战 · Shannon's Blog

    前言:iOS 开发中,h5 和原生实现通信有多种方式, JSBridge 就是最常用的一种,各 JSBridge 类库的实现原理大同小异,这篇文章主要是针对当前使用最为广泛的 WebViewJavas ...

  4. 8——PHP循环结构&&条件结构

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  5. python基础-流程控制语句

    所谓流程控制,就是在程序里面设定一些条件判断语句,满足哪条,就执行哪条 #if 单分支 if 条件: 满足条件后执行的代码 #例子 > : print()#结果为666 双分支 if 条件: 满 ...

  6. 身为 Java 程序员必须掌握的 10 款开源工具!

    本文主要介绍Java程序员应该在Java学习过程中的一些基本和高级工具.如果你是一位经验丰富的Java开发人员,你可能对这些工具很熟悉,但如果不是,现在就是是开始学习这些工具的好时机.Java世界中存 ...

  7. Ubutun18.04安装Python3.7.6

    最近因为环境问题,简单记录下Python3.7的安装过程: 下载地址:http://python.org/ftp/python/3.7.6/Python-3.7.6.tgz 编译安装步骤: sudo ...

  8. JavaScript实现栈结构(Stack)

    JavaScript实现栈结构(Stack) 一.前言 1.1.什么是数据结构? 数据结构就是在计算机中,存储和组织数据的方式. 例如:图书管理,怎样摆放图书才能既能放很多书,也方便取? 主要需要考虑 ...

  9. Flex布局做出自适应页面--语法和案例

    本文发布在: github项目地址:https://github.com/tenadolanter/flex-layout-demo SegmentFault地址:https://segmentfau ...

  10. 纯JS实现KeyboardNav(学习笔记)一

    纯JS实现KeyboardNav(学习笔记)一 这篇博客只是自己的学习笔记,供日后复习所用,没有经过精心排版,也没有按逻辑编写 GitHub项目源码 预览地址 最终效果 KeyboardNav使用指南 ...