Coconuts HDU - 5925 二维离散化 自闭了
Now TanBig wants to know how many times he needs to eat all the good coconuts in the field, and how many coconuts he would eat each time(the area of each 4-connected component).
InputThe first line contains apositiveinteger T(T≤10T≤10) which denotes the test cases. T test cases begin from the second line. In every test case, the first line contains two integers R and C, 0<R,C≤1090<R,C≤109 the second line contains an integer n, the number of bad coconuts, 0≤n≤2000≤n≤200 from the third line, there comes n lines, each line contains two integers, xixi and yiyi, which means in cell(xi,yixi,yi), there is a bad coconut.
It is guaranteed that in the input data, the first row and the last row will not have bad coconuts at the same time, the first column and the last column will not have bad coconuts at the same time. 
OutputFor each test case, output "Case #x:" in the first line, where x denotes the number of test case, one integer k in the second line, denoting the number of times TanBig needs, in the third line, k integers denoting the number of coconuts he would eat each time, you should output them in increasing order.Sample Input
2 3 3
2
1 2
2 1 3 3
1
2 2
Sample Output
Case #1:
2
1 6
Case #2:
1
8
题意
青蛙先生的朋友TanBig非常喜欢吃东西,所以他总是喜欢吃东西。
有一天,TanBig梦想着一片椰子,这个领域看起来像一个有R行和C列的大棋盘。
在田地的每个细胞中,都有一个椰子。 不幸的是,一些椰子变质了。 为了他的健康,
TanBig将按照他只能吃好椰子的规则来吃椰子,并且一次只能吃好椰子的连接成分
(你可以认为坏椰子是障碍,而好的椰子是4- 连接,这意味着单元格(x,y)
中的一个椰子连接到(x-1,y),(x + 1,y),(x,y + 1),(x,y-1)。
现在TanBig想知道他需要多少次吃掉田里所有好吃的椰子,以及每次吃多少椰子(每个4个连接组件的面积)。
其实就是让你求出每一个联通快的大小
因为 R C <= 1e9 所以必须离散化 自闭拉 自闭拉 完全不会啊
只能看题解为生 题目补不完了 二维离散化一下 因为点最多有是一个300*300的矩阵
离散化后用一个cntx,cnty,分别记录每一个格子压缩前的面积
然后就是最裸的DFS计算联通快就行了 注意一下最后的答案要从小到大输出
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("DATA.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x7fffffff;
const int mod = 1e9 + ;
const int maxn = ;
int t, cas = , R, C, n, pointx[maxn], pointy[maxn], x[maxn], y[maxn], vis[maxn][maxn];
map<LL, LL>mpx, mpy;
vector<int>cntx, cnty;
int dx[] = {, , , -};
int dy[] = {, -, , };
LL sum = ;
void dfs(int x, int y) {
vis[x][y] = ;
sum += 1LL * cntx[x] * cnty[y];
for (int i = ; i < ; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx >= && nx < cntx.size() && ny >= && ny < cnty.size() && !vis[nx][ny]) dfs(nx, ny);
}
}
void init(){
mpx.clear(),mpy.clear();
cntx.clear(),cnty.clear();
mem(vis,);
}
LL ans[maxn];
int main() {
sf(t);
while(t--) {
sff(R, C);
sf(n);
init();
int cnt1 = , cnt2 = ;
x[cnt1++] = , x[cnt1++] = R;
y[cnt2++] = , y[cnt2++] = C;
for (int i = ; i <= n ; i++) {
sff(pointx[i], pointy[i]);
x[cnt1++] = pointx[i];
y[cnt2++] = pointy[i];
}
sort(x, x + cnt1);
sort(y, y + cnt2);
cnt1 = unique(x, x + cnt1) - x;
cnt2 = unique(y, y + cnt2) - y;
for (int i = ; i < cnt1 ; i++) {
int len = x[i] - x[i - ];
if (len > ) cntx.push_back(len - );
cntx.push_back();
mpx[x[i]] = cntx.size() - ;
}
for (int i = ; i < cnt2 ; i++) {
int len = y[i] - y[i - ];
if (len > ) cnty.push_back(len - );
cnty.push_back();
mpy[y[i]] = cnty.size() - ;
}
for (int i = ; i <= n ; i++)
vis[mpx[pointx[i]]][mpy[pointy[i]]] = ;
int k = ;
for (int i = ; i < cntx.size() ; i++) {
for (int j = ; j < cnty.size() ; j++) {
if (!vis[i][j]) {
sum = ;
dfs(i, j);
ans[k++] = sum;
}
}
}
sort(ans,ans+k);
printf("Case #%d:\n", cas++);
printf("%d\n",k);
for (int i = ; i < k ; i++)
printf("%lld%c", ans[i], i == k - ? '\n' : ' ');
}
return ;
}
Coconuts HDU - 5925 二维离散化 自闭了的更多相关文章
- Coconuts HDU - 5925 (二维离散化求连通块的个数以及大小)
		
题目链接: D - Coconuts HDU - 5925 题目大意:首先是T组测试样例,然后给你n*m的矩阵,原先矩阵里面都是白色的点,然后再输入k个黑色的点.这k个黑色的点可能会使得原先白色的点 ...
 - HDU 2159 二维费用背包问题
		
一个关于打怪升级的算法问题.. 题意:一个人在玩游戏老是要打怪升级,他愤怒了,现在,还差n经验升级,还有m的耐心度(为零就删游戏不玩了..),有m种怪,有一个最大的杀怪数s(杀超过m只也会删游戏的.. ...
 - hdu 4819 二维线段树模板
		
/* HDU 4819 Mosaic 题意:查询某个矩形内的最大最小值, 修改矩形内某点的值为该矩形(Mi+MA)/2; 二维线段树模板: 区间最值,单点更新. */ #include<bits ...
 - F - F HDU - 1173(二维化一维-思维)
		
F - F HDU - 1173 一个邮递员每次只能从邮局拿走一封信送信.在一个二维的直角坐标系中,邮递员只能朝四个方向移动,正北.正东.正南.正西. 有n个需要收信的地址,现在需要你帮助找到一个地方 ...
 - HDU 3496 (二维费用的01背包) Watch The Movie
		
多多想看N个动画片,她对这些动画片有不同喜欢程度,而且播放时长也不同 她的舅舅只能给她买其中M个(不多不少恰好M个),问在限定时间内观看动画片,她能得到的最大价值是多少 如果她不能在限定时间内看完买回 ...
 - hdu 2642 二维树状数组 单点更新区间查询 模板水题
		
Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Subm ...
 - hdu 2888 二维RMQ模板题
		
Check Corners Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
 - HDU 1263 二维map
		
题意:给出一份水果的交易表,根据地区统计出水果的交易情况. 思路:二维map使用. #include<cstdio> #include<string> #include ...
 - hdu 2888 二维RMQ
		
Check Corners Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
 
随机推荐
- fizzbuzz Python很有意思的解法
			
写一个程序,打印数字1到100,3的倍数打印“Fizz”来替换这个数,5的倍数打印“Buzz”,对于既是3的倍数又是5的倍数的数字打印“FizzBuzz” 题目不难,解起来容易,用for循环做if,e ...
 - HDU - 6409:没有兄弟的舞会(数学+思维)
			
链接:HDU - 6409:没有兄弟的舞会 题意: 题解: 求出最大的 l[i] 的最大值 L 和 r[i] 的最大值 R,那么 h 一定在 [L, R] 中.枚举每一个最大值,那么每一个区间的对于答 ...
 - 理解Python中的__builtin__和__builtins__
			
以Python 2.7为例,__builtin__模块和__builtins__模块的作用在很多情况下是相同的. 但是,在Python 3+中,__builtin__模块被命名为builtins. 所 ...
 - 《Linux/UNIX系统编程手册》读书笔记
			
2018-1-30 一.UNIX.C语言以及Linux的历史回顾 1. UNIX简史.C语言的诞生 1969年,贝尔实验室的Ken Thompson首次实现了UNIX系统. 1973年,C语言步入成熟 ...
 - Debian常用软件
			
1. 有道词典 https://github.com/justzx2011/openyoudao
 - Token安全
			
token相对安全加密算法 http://blog.csdn.net/q8649912/article/details/52370565 关于文章的理解 1 sessionid 这个名词应该理解为:一 ...
 - 【Linux】- Ubutnu UFW防火墙的简单设置
			
ufw是一个主机端的iptables类防火墙配置工具,比较容易上手.一般桌面应用使用ufw已经可以满足要求了. 安装方法 sudo apt-get install ufw 使用方法 1.启用: sud ...
 - python数据类型二
			
阅读目录 1.列表的去嵌套 2.元组 3.range 列表的增删改查 一,增: 注意 list和str是不一样的,lst可以发生改变,所以直接就在原来的对象上进行可操作 追加模式 lst = ['麻 ...
 - React Components Template
			
React Components Template "use strict"; /** * * @author xgqfrms * @license MIT * @copyrigh ...
 - 【bzoj3732】Network  最小生成树+倍增LCA
			
题目描述 给你N个点的无向图 (1 <= N <= 15,000),记为:1…N. 图中有M条边 (1 <= M <= 30,000) ,第j条边的长度为: d_j ( 1 & ...