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 ...
随机推荐
- ionic 提示框
html文件 <ion-header> <ion-navbar> <ion-title>Toast</ion-title> </ion-navba ...
- mysql 按日期统计
按年汇总,统计: select sum(mymoney) as totalmoney, count(*) as sheets from mytable group by date_format(col ...
- 幸运的袋子(深度优先遍历(Depth First Search,DFS))
题目描述 一个袋子里面有n个球,每个球上面都有一个号码(拥有相同号码的球是无区别的).如果一个袋子是幸运的当且仅当所有球的号码的和大于所有球的号码的积. 例如:如果袋子里面的球的号码是{1, 1, 2 ...
- 56[LeetCode] .Merge Intervals
Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums s ...
- [转载]Java集合框架的常见面试题
http://www.jfox.info/40-ge-java-ji-he-lei-mian-shi-ti-he-da-an 整理自上面链接: Java集合框架为Java编程语言的基础,也是Java面 ...
- Struts2中Action各种转发类型
Struts2:Action中result的各种转发类型: 内部请求转发dispatcher(默认值) redirect.redirectAction.plainText1.redirect是重定向到 ...
- VBA基础之Excel VBA 表格的操作(一)
一.Excel VBA 表格的操作1. Excel表格的指定以及表格属性的设置 Sub main() '把表格B2的值改为"VBA Range和Cells函数" Range(&qu ...
- Python练习—循环
1.输入n的值,求出n的阶乘. s=1 n = int(input("请输入一个数")) for i in range(1,n+1): s=s*i print(s) 2.折纸上月球 ...
- 互评Alpha版本——Thunder团队
基于NABCD评论作品 Hello World! :http://www.cnblogs.com/120626fj/p/7807544.html 欢迎来怼 :http://www.cnblogs.co ...
- CSS基础小记
2017/10/29 CSS 认识CSS样式 CSS全称为"层叠样式表 (Cascading Style Sheets)",它主要是用于定义HTML内容在浏览器内的显示样式,如文字 ...