[枚举] 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
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.
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.
0 0 1 1
2 2 3 4
1 0 3 2
0 1 2 3
0 0 1 1
0 0 1 1
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的更多相关文章
- 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 ...
- 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 ...
- 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) ...
- HDU 6395 2018 Multi-University Training Contest 7 (快速幂+分块)
原题地址 Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- 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 ...
- 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/ ...
- 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 ...
- 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.输出 ...
- 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)个点(选出的点只 ...
随机推荐
- 80 remove duplicates from sorted array 2
| 分类 leetcode | Follow up for "Remove Duplicates": What if duplicates are allowed at most ...
- charles添加https支持
- 【Git】按照git提交ID导出修改的代码
#!/bin/bash IFS=$'\n' #conf start commid id startCommitId=030cd2bf4e3694fe3a3b6f069556c4ea91a9858d l ...
- Python爬虫 - UserAgent列表
PC端: PC_USER_AGENT = [ 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)', 'Mozilla/4.0 (compatibl ...
- Python 获取MySql某个表所有字段名
在使用python导出数据库中数据的时候,往往除了插入的数据以外,还有表字段等信息需要导出,查阅了资料后发现了2种方法 第一种:在mysql自带的表里查询,这个表保存了每张表的字段信息,可以用pymy ...
- webpack的loader和plugin的区别
[Loader]:用于对模块源码的转换,loader描述了webpack如何处理非javascript模块,并且在buld中引入这些依赖.loader可以将文件从不同的语言(如TypeScript)转 ...
- Spark RDD Tutorial
Spark RDD教程 这个教程将会帮助你理解和使用Apache Spark RDD.所有的在这个教程中使用的RDD例子将会提供在github上,供大家快速的浏览. 什么是RDD(Rssilient ...
- DBA_Oracle DBA常用表汇总(概念)--转载
https://www.cnblogs.com/eastsea/p/3799411.html 一.与权限相关的字典 ALL_COL_PRIVS表示列上的授权,用户和PUBLIC是被授予者 ALL_C ...
- [Python] iupdatable包:File模块使用介绍
一.简介 文件模块主要是对常见的文件读写功能进行了封装,默认使用UTF8(utf_8_sig)格式编码,实现一行代码读写文件. 二.简单示例 安装 iupdatable 包 pip install - ...
- C语言二进制拼接 (整数和byte类型的字符串拼接)
#include <iostream>#include <cstring>#include <cstdio> using namespace std; typede ...