TanBig, a friend of Mr. Frog, likes eating very much, so he always has dreams about eating. One day, TanBig dreams of a field of coconuts, and the field looks like a large chessboard which has R rows and C columns. In every cell of the field, there is one coconut. Unfortunately, some of the coconuts have gone bad. For sake of his health, TanBig will eat the coconuts following the rule that he can only eat good coconuts and can only eat a connected component of good coconuts one time(you can consider the bad coconuts as barriers, and the good coconuts are 4-connected, which means one coconut in cell (x, y) is connected to (x - 1, y), (x + 1, y), (x, y + 1), (x, y - 1).

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 二维离散化 自闭了的更多相关文章

  1. Coconuts HDU - 5925 (二维离散化求连通块的个数以及大小)

    题目链接: D - Coconuts  HDU - 5925 题目大意:首先是T组测试样例,然后给你n*m的矩阵,原先矩阵里面都是白色的点,然后再输入k个黑色的点.这k个黑色的点可能会使得原先白色的点 ...

  2. HDU 2159 二维费用背包问题

    一个关于打怪升级的算法问题.. 题意:一个人在玩游戏老是要打怪升级,他愤怒了,现在,还差n经验升级,还有m的耐心度(为零就删游戏不玩了..),有m种怪,有一个最大的杀怪数s(杀超过m只也会删游戏的.. ...

  3. hdu 4819 二维线段树模板

    /* HDU 4819 Mosaic 题意:查询某个矩形内的最大最小值, 修改矩形内某点的值为该矩形(Mi+MA)/2; 二维线段树模板: 区间最值,单点更新. */ #include<bits ...

  4. F - F HDU - 1173(二维化一维-思维)

    F - F HDU - 1173 一个邮递员每次只能从邮局拿走一封信送信.在一个二维的直角坐标系中,邮递员只能朝四个方向移动,正北.正东.正南.正西. 有n个需要收信的地址,现在需要你帮助找到一个地方 ...

  5. HDU 3496 (二维费用的01背包) Watch The Movie

    多多想看N个动画片,她对这些动画片有不同喜欢程度,而且播放时长也不同 她的舅舅只能给她买其中M个(不多不少恰好M个),问在限定时间内观看动画片,她能得到的最大价值是多少 如果她不能在限定时间内看完买回 ...

  6. hdu 2642 二维树状数组 单点更新区间查询 模板水题

    Stars Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others) Total Subm ...

  7. hdu 2888 二维RMQ模板题

    Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  8. HDU 1263 二维map

    题意:给出一份水果的交易表,根据地区统计出水果的交易情况.   思路:二维map使用.   #include<cstdio> #include<string> #include ...

  9. hdu 2888 二维RMQ

    Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. TW实习日记:第31-32天

    不知不觉的,实习的净工作天数,已经都超过一个月了.因为对工作内容不是很满意,所以打算月底离职,也不知道是公司太缺人还是我真的能干活,领导竟然三番两次找我让我再考虑...明天又要找我了,哎...随机应变 ...

  2. 硬盘基础知识&&分区

    学习记录的笔记,虽然毫无章法 硬盘基础知识 磁盘的物理组成 如下图所示: 有关磁盘物理知识的详细介绍请看硬盘的存储原理和内部架构这篇博文 硬盘接口类型 IDE SATA SCSI SAS 光纤通道 I ...

  3. Memcache的客户端连接系列(一) Java

    声明:本文并非原创,转自华为云帮助中心的分布式缓存服务(Memcached)的用户指南. 关键词: Memcached  客户端 Java Java连接池 Java客户端示例 用户的弹性云服务器已安装 ...

  4. nodejs笔记--基础篇(一)

    Sublime Node.js开发环境配置 下载并安装Node.js安装包后再开始配置 1.先安装好Sublime Text 2 2.运行Sublime,菜单上找到Tools ---> Buil ...

  5. 在JS中 实现不用中间变量temp 实现两个变量值得交换

    1.使用加减法; var a=1; var b=2; a=a+b; b=a-b; a=a-b; 2.使用乘除法(乘除法更像是加减法向乘除运算的映射) var a=1; var b=2; a = a * ...

  6. 项目uml

    [团队信息] 团队项目: 小葵日记--主打记录与分享模式的日记app 队名:日不落战队 队员信息及贡献分比例: 短学号 名 本次作业博客链接 此次作业任务 贡献分配 备注 501 安琪 http:// ...

  7. <Android>日期,时间选择对话框

    a)         调用Activity的onCreateDialog()方法创建对话框 b)        分别在OnDateSetListener的onDateSet()方法和OnTimeSet ...

  8. 修改IntelliJ IDEA字体

  9. Perfmon - 脚本自动监控

    PerfMon-Windows性能监视器是个好东西,可以辅助我们分析发生问题时间段服务器资源占用情况,但是部署性能计数器确实一个相当麻烦的事情,往往这种枯燥的事别人还做不了,只能由我们这些希望获取到P ...

  10. monaco editor 实现自定义提示(sql为例)

    monaco editor :https://www.cnblogs.com/XHappyness/p/9414177.html 这里实现自己定义的提示: .vue <template> ...