Coconuts

Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Problem Description
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).

 
Input
The first line contains apositiveinteger T(T≤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≤109 the second line contains an integer n, the number of bad coconuts, 0≤n≤200 from the third line, there comes n lines, each line contains two integers, xi and yi, which means in cell(xi,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.

 
Output
For
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
 
Source
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=1e3+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
int n,m,q;
struct point
{
int x,y;
}a[N];
ll l[N];
int getpos(int x,int flag)
{
return lower_bound(l,l+flag,x)-l;
}
int mp[N][N];
int vis[N][N];
int xx[]={,,,-};
int yy[]={-,,,};
int flag;
int nn,mm;
int check(int x,int y)
{
if(x<||x>nn||y<||y>mm)
return ;
return ;
}
void dfs(int n,int m,int deep)
{
vis[n][m]=deep;
for(int i=;i<;i++)
{
int xxx=n+xx[i];
int yyy=m+yy[i];
if(check(xxx,yyy)&&!mp[xxx][yyy]&&!vis[xxx][yyy])
{
dfs(xxx,yyy,deep);
}
}
}
ll ans[];
ll getnum(int x)
{
if(x==)
return l[x];
return l[x]-l[x-];
}
int main()
{
int T,cas=;
scanf("%d",&T);
while(T--)
{
flag=;
memset(mp,,sizeof(mp));
memset(vis,,sizeof(vis));
memset(ans,,sizeof(ans));
int kuai=;
scanf("%d%d",&n,&m);
scanf("%d",&q);
for(int i=;i<=q;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
l[flag++]=a[i].x;
l[flag++]=a[i].y;
if(a[i].x+<=n)
l[flag++]=a[i].x+;
if(a[i].y+<=m)
l[flag++]=a[i].y+;
if(a[i].x-)
l[flag++]=a[i].x-;
if(a[i].y-)
l[flag++]=a[i].y-;
}
l[flag++]=;
if(n>=||m>=)
l[flag++]=;
l[flag++]=n;
l[flag++]=m;
sort(l,l+flag);
flag=unique(l,l+flag)-l;
for(int i=;i<=q;i++)
{
mp[getpos(a[i].x,flag)][getpos(a[i].y,flag)]=;
}
nn=getpos(n,flag);
mm=getpos(m,flag);
for(int i=;i<=nn;i++)
{
for(int t=;t<=mm;t++)
{
if(!mp[i][t]&&!vis[i][t])
{
dfs(i,t,kuai++);
}
}
}
for(int i=;i<=nn;i++)
{
for(int t=;t<=mm;t++)
{
if(vis[i][t])
{
ans[vis[i][t]]+=getnum(i)*getnum(t);
}
}
}
printf("Case #%d:\n",cas++);
printf("%d\n",kuai-);
if(kuai-)
{
sort(ans+,ans+kuai);
printf("%lld",ans[]);
for(int i=;i<kuai;i++)
printf(" %lld",ans[i]);
printf("\n");
}
}
return ;
}

hdu 5925 Coconuts 离散化+dfs的更多相关文章

  1. HDU 5925 Coconuts 离散化

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5925 Coconuts Time Limit: 9000/4500 MS (Java/Others) ...

  2. HDU 5925 Coconuts 【离散化+BFS】 (2016CCPC东北地区大学生程序设计竞赛)

    Coconuts Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  3. HDU 5925 Coconuts

    2016 CCPC 东北四省赛 D. 一道好题. 现场写崩了. 赛后LSh跟我讲了一种离散化的做法, 没听懂. 题意 一个\(R \cdot C\ (R, C\le 10^9)\) 的矩形点阵上有 $ ...

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

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

  5. hdu4605 树状数组+离散化+dfs

    Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  6. HDOJ(HDU).2660 Accepted Necklace (DFS)

    HDOJ(HDU).2660 Accepted Necklace (DFS) 点我挑战题目 题意分析 给出一些石头,这些石头都有自身的价值和重量.现在要求从这些石头中选K个石头,求出重量不超过W的这些 ...

  7. HDOJ(HDU).1045 Fire Net (DFS)

    HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...

  8. HDOJ(HDU).1241 Oil Deposits(DFS)

    HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  9. HDOJ(HDU).1035 Robot Motion (DFS)

    HDOJ(HDU).1035 Robot Motion [从零开始DFS(4)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DF ...

随机推荐

  1. 【secureCRT】会话保存的路径

  2. scala匿名函数

    package com.ming.test import scala.math._ object AnonymousFunc { def valueAtOneQuarter(f:(Double)=&g ...

  3. Dynamics AX 2012 R2 在报表上显示和打印条码

        AX中有对条码操作的封装,用其生成BarCodeString类型的值,再配合barcode128字体,即可在显示出条码.     废话不说,上代码. BarcodeCode128 barCod ...

  4. 【Pro ASP.NET MVC 3 Framework】.学习笔记.5.SportsStore一个真实的程序

    我们要建造的程序不是一个浅显的例子.我们要创建一个坚固的,现实的程序,坚持使它成为最佳实践.与Web Form中拖控件不同.一开始投入MVC程序付出利息,它给我们可维护的,可扩展的,有单元测试卓越支持 ...

  5. Mac系统之----教你怎么显示隐藏文件,或者关闭显示隐藏文件

    缺省情况下,在 Mac 下是不显示隐藏文件的,Finder 也未提供设置是否显示隐藏文件的选项,不像 Windows 下,有一个“文件夹选项“设置界面里可以控制,但这并不表示 Mac 下无法显示隐藏文 ...

  6. docker stop 与 docker kill的区别

    docker stop 与 docker kill 均可以将容器停掉,但二者究竟有什么区别呢?首先,摘录一下官网对这两个功能的描述: docker stop: Stop a running conta ...

  7. div使用jqueryui 源码 | gridview多个功能的源码

    div使用jqueryui 源码 | gridview多个功能的源码 一.gridview 选中行 改变颜色,双击选中 改变颜色 protected void gv1_SelectedIndexCha ...

  8. mysql高可用之PXC(Percona XtraDB Cluster)

    简介 Percona XtraDB Cluster是MySQL高可用性和可扩展性的解决方案,Percona XtraDB Cluster提供的特性如下: 1).同步复制,事务要么在所有节点提交或不提交 ...

  9. JavaScript push()和splice()方法

    JavaScript push() 方法 定义和用法 push() 方法可向数组的末尾添加一个或多个元素,并返回新的长度. 语法 arrayObject.push(newelement1,newele ...

  10. [ios][opengles]opengles纹理贴图

    参考:http://www.cnblogs.com/andyque/archive/2011/09/02/2155061.html