2019 杭电多校 8 1009

题目链接:HDU 6665

比赛链接:2019 Multi-University Training Contest 8

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\le T\le 10000)\), the number of test cases.

Each test case contains two lines, specifying the two rectangles. Each line contains four integers \(x_1,y_1,x_2,y_2 (0\le x_1,y_1,x_2,y_2\le 10^9,x_1<x_2,y_1<y_2)\), where \((x_1,y_1),(x_2,y_2)\) 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

Solution

题意:

给出两个矩形,求矩形把平面分割成几块。

思路

分类讨论

听说只要离散化到 \(5*5\) 的格子里然后 \(DFS\) 就可以了,有空再补。

#include <bits/stdc++.h>
using namespace std; typedef long long ll; const ll inf = 0x3f3f3f3f; struct Point
{
ll x, y;
}p[10]; int main() {
int T;
cin >> T;
while (T--) {
ll maxx = 0, maxy = 0, minx = inf, miny = inf;
for(int i = 1; i <= 2; ++i) {
scanf("%lld%lld", &p[i].x, &p[i].y);
}
p[3].x = p[1].x;
p[3].y = p[2].y;
p[4].x = p[2].x;
p[4].y = p[1].y;
ll s1 = (p[2].x - p[1].x) * (p[2].y - p[1].y); for(int i = 5; i <= 6; ++i) {
scanf("%lld%lld", &p[i].x, &p[i].y);
}
p[7].x = p[5].x;
p[7].y = p[6].y;
p[8].x = p[6].x;
p[8].y = p[5].y;
ll s2 = (p[6].x - p[5].x) * (p[6].y - p[5].y); for(int i = 1; i <= 8; ++i) {
maxx = max(maxx, p[i].x);
maxy = max(maxy, p[i].y);
minx = min(minx, p[i].x);
miny = min(miny, p[i].y);
} // for(int i = 1; i <= 8; ++i) {
// cout << p[i].x << " " << p[i].y << endl;
// } if(p[1].x == p[5].x && p[1].y == p[5].y && p[3].x == p[7].x && p[3].y == p[7].y && p[6].x == p[2].x && p[6].y == p[2].y && p[4].x == p[8].x && p[4].y == p[8].y) {
printf("2\n");
continue;
}
ll s = (maxx - minx) * (maxy - miny); // cout << s << endl;
if(s1 == s || s2 == s) {
if((p[1].x == p[5].x && p[2].x == p[6].x)) {
if(p[5].y == p[1].y || p[6].y == p[2].y) printf("3\n");
else printf("4\n");
} else if((p[1].y == p[5].y && p[2].y == p[6].y)) {
if(p[5].x == p[1].x || p[6].x == p[2].x) printf("3\n");
else printf("4\n");
}
else printf("3\n");
} else if(p[4].y >= p[7].y || p[8].y >= p[3].y || p[5].x >= p[2].x || p[1].x >= p[6].x) {
printf("3\n");
} else if((p[2].x - p[1].x) * (p[6].y - p[5].y) == s) {
if(p[6].y > p[2].y && p[5].y < p[1].y && p[1].x < p[5].x && p[2].x > p[6].x) {
printf("6\n");
} else if(p[1].x == p[5].x && p[1].y == p[5].y) {
printf("4\n");
} else if(p[3].x == p[7].x && p[3].y == p[7].y) {
printf("4\n");
} else if(p[2].x == p[6].x && p[2].y == p[6].y) {
printf("4\n");
} else if(p[4].x == p[8].x && p[4].y == p[8].y) {
printf("4\n");
} else {
printf("5\n");
}
} else if((p[6].x - p[5].x) * (p[2].y - p[1].y) == s) {
if(p[2].y > p[6].y && p[1].y < p[5].y && p[5].x < p[1].x && p[6].x > p[2].x) {
printf("6\n");
} else if(p[1].x == p[5].x && p[1].y == p[5].y) {
printf("4\n");
} else if(p[3].x == p[7].x && p[3].y == p[7].y) {
// cout << 1 << endl;
printf("4\n");
} else if(p[2].x == p[6].x && p[2].y == p[6].y) {
printf("4\n");
} else if(p[4].x == p[8].x && p[4].y == p[8].y) {
printf("4\n");
} else {
printf("5\n");
}
} else {
printf("4\n");
}
} return 0;
}

HDU 6665 Calabash and Landlord (分类讨论)的更多相关文章

  1. 2019 杭电多校第八场 HDU - 6665 Calabash and Landlord 两矩形分平面

    题意 给出两个矩形,问这两个矩形把平面分成了几部分. 分析 不需要什么高级技能,只需 “简单” 的分类讨论. (实在太难写了,对拍找出错误都不想改 推荐博客,其中有个很好的思路,即只讨论答案为2,3, ...

  2. HDU 5705 Clock(模拟,分类讨论)

    Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submi ...

  3. HDU 5203 Rikka with wood sticks 分类讨论

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5203 bc(chinese):http://bestcoder.hdu.edu.cn/con ...

  4. HDU 6627 equation (分类讨论)

    2019 杭电多校 5 1004 题目链接:HDU 6627 比赛链接:2019 Multi-University Training Contest 5 Problem Description You ...

  5. [枚举] 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/ ...

  6. HDU5957 Query on a graph(拓扑找环,BFS序,线段树更新,分类讨论)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5957 题意:D(u,v)是节点u和节点v之间的距离,S(u,v)是一系列满足D(u,x)<=k的点 ...

  7. Codeforces 460D Little Victor and Set --分类讨论+构造

    题意:从区间[L,R]中选取不多于k个数,使这些数异或和尽量小,输出最小异或和以及选取的那些数. 解法:分类讨论. 设选取k个数. 1. k=4的时候如果区间长度>=4且L是偶数,那么可以构造四 ...

  8. BZOJ-1067 降雨量 线段树+分类讨论

    这道B题,刚的不行,各种碎点及其容易忽略,受不鸟了直接 1067: [SCOI2007]降雨量 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 2859 ...

  9. UVaLive 6862 Triples (数学+分类讨论)

    题意:给定一个n和m,问你x^j + y^j = z^j 的数量有多少个,其中0 <= x <= y <= z <= m, j = 2, 3, 4, ... n. 析:是一个数 ...

随机推荐

  1. Qt获取文件路径、文件夹路径

    1.首先是选择文件 QString file_path = QFileDialog::getOpenFileName(this, "请选择文件路径...", "默认路径( ...

  2. PAT 1051 Pop Sequence (25 分)

    返回 1051 Pop Sequence (25 分)   Given a stack which can keep M numbers at most. Push N numbers in the ...

  3. c/c++ int 范围的原因

    在C语言中, signed char 类型的范围为-128~127,每本教科书上也这么写,但是没有哪一本书上(包括老师)也不会给你为什么是-128~127,这个问题貌似看起来也很简单容易, 以至于不用 ...

  4. 1. 什么是Prometheus

    什么是Prometheus Prometheus是一个最初在SoundCloud上构建的开源系统监视和警报工具包 .自2012年成立以来,许多公司和组织都采用了Prometheus,该项目拥有一个非常 ...

  5. Jlink 接口定义

    JTAG有10pin的.14pin的和20pin的,尽管引脚数和引脚的排列顺序不同,但是其中有一些引脚是一样的,各个引脚的定义如下. 1. 引脚定义 Test Clock Input (TCK) -- ...

  6. Java学习第一次总结

    在此之前我需要声明一下,我不载过多的评论知识点的简单与难易程度.写出来只是为了方便使用,现阶段追求的是实在.㈠①自动类型转换由低到高byte.short.char→int→long→flot→doub ...

  7. awk 按小时 统计接口调用次数

    #统计所有接口总量awk -F ' ' '{a[$7]++} END{for(i in a){print i,a[i] | "sort -r -k 7"}}' accesslog/ ...

  8. python-模块 time, os, sys

    时间模块 和时间有关系的我们就要用到时间模块.在使用模块之前,应该首先导入这个模块. #常用方法 1.time.sleep(secs) (线程)推迟指定的时间运行.单位为秒. 2.time.time( ...

  9. CF1163E

    CF1163E 首先存在p的要求是能建一个满的线性基而且线性基用到的数不能大于等于\(2^x\) 这很好解决,只要把所有数排序后从小到大的插进线性基,然后每次删掉所有原数大于\(2^x\)的数并调整x ...

  10. linux下samba共享服务器搭建详解

    这两天业务需求搭了一台服务器.要求samba共享文件. 葡萄美酒月光杯的前戏就省了,我们直接上干货. 1.yum方式安装samba yum  -y  install samba 2.将/etc/sam ...