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 ...
随机推荐
- 【system.number】使用说明
对象:system.number 说明:提供一系列针对数值类型的操作 目录: 方法 返回 说明 system.number.isNumber( number ) [True | False] 检测是否 ...
- 365. Count 1 in Binary【LintCode java】
Description Count how many 1 in binary representation of a 32-bit integer. Example Given 32, return ...
- win7下本地运行spark以及spark.sql.warehouse.dir设置
SparkSession spark = SparkSession .builder() .master("local[*]") .enableHiveSupport() .con ...
- OpenMPI源码剖析1:MPI_Init初探
OpenMPI的底层实现: 我们知道,OpenMPI应用起来还是比较简单的,但是如果让我自己来实现一个MPI的并行计算,你会怎么设计呢?————这就涉及到比较底层的东西了. 回想起我们最简单的代码,通 ...
- 通过Ajax上传文件至WebApi服务器
https://stackoverflow.com/questions/43013858/ajax-post-a-file-from-a-form-with-axios var formData = ...
- Thunder团队第五周 - Scrum会议2
Scrum会议2 小组名称:Thunder 项目名称:i阅app Scrum Master:胡佑蓉 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传 ...
- PHPCMS v9的表单向导实现问答咨询功能的方法
本文主要介绍了在phpcms v9的表单向导里实现问答咨询功能的方法 phpcms v9内容管理系统本身是没有问答模块的,只有表单向导,但表单向导有很大的局限性,通过表单向导,我们只能查看用户提交的信 ...
- Daily Scrum 10
今天我们小组开会内容分为以下部分: part 1: 经过反复思考,对于上次组会确定的在系统中加入娱乐版块进行了更进一步的商讨; part 2:继续探讨算法实现: part 3:进行明日的任务分配; ◆ ...
- iOS- UIScrollView、UIPageControl分页浏览图片
1.先介绍下UIScrollView的常见属性 @property(nonatomic) CGPoint contentOffset; // 记录UIScrollView滚动的位置 @property ...
- Vue自定义事件,$on(eventName) 监听事件,$emit(eventName) 触发事件
<!--自定义事件 使用 $on(eventName) 监听事件 使用 $emit(eventName) 触发事件--> <div id="app15"> ...