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. php 字符串 定界符 json_last_error()

    字符串的3种赋值 1:单引号 $str = '111111111111 '; 2:双引号 $str =" 11111111111 "; 3:定界符 $str = <<& ...

  2. linux卸载

    centos平台 yum remove xxxrpm包,rpm -e xxxtar包直接删除该文件或者make uninstall xxx

  3. Area--->AreaRegister.RegisterAllArea()与Area区域的解析

    文章引导 MVC路由解析---IgnoreRoute MVC路由解析---MapRoute MVC路由解析---UrlRoutingModule Area的使用 Area--->AreaRegi ...

  4. Cococs2d-x学习路线

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. Cocos2D-X推荐书: Cocos2d-x权威指南

  5. Windows7下移植Qt4.8.4项目到QT5.2上时遇到的一些问题

        最近在Windows7下将Qt4.8.4+MSVC2008的项目移植到QT5.2下时,遇到了一些小问题: 问题一:错误:C1083: 无法打开包括文件:"QApplication&q ...

  6. 2059-authentication plugin 'caching_sha2_password"cnnot bt loaded :mysql8.0数据库连接不上(Navicat)

    原因:8.0改变了 身份验证插件 , 打开 my.ini (或者my.cofg) 可以看到变更了 5.7及其以前的方式:mysql_native_password 办法: 1:命令行键入数据库: my ...

  7. 数据结构与算法简记--Trie树

    Trie树 概念 多叉树,节点为字符串中的单个字符. Trie 树的本质,就是利用字符串之间的公共前缀,将重复的前缀合并在一起. 将多个字符串按字符拆分插入Trie树,用于字符串查找,关键词提示等 举 ...

  8. JsonSchema 启蒙

    jsonSchema 的应用场景有很多,毕竟现在各个接口传输数据基本都是json,比如你做测试想对部分json字段进行校验或者统计你该如何写?解析json获取字段然后if else?不是说不可以但是也 ...

  9. 服务bindService()方法启动服务

    public class MainActivity extends Activity { private EditText studentno; private ServiceConnection c ...

  10. hdu 5792 线段树+离散化+思维

    题目大意: Given a sequence A with length n,count how many quadruple (a,b,c,d) satisfies: a≠b≠c≠d,1≤a< ...