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 ...
随机推荐
- ajax 个人理解 学习笔记
W:Ajax Q:异步网络请求.无刷新请求数据. W:ajax的实现流程如下: Q: 创建XHR对象 调用open()方法,创建请求 调用send()方法,发送请求 捕获请求状态,判断请求结果 获取数 ...
- FFM
转载自http://blog.csdn.net/jediael_lu/ https://blog.csdn.net/jediael_lu/article/details/77772565 点击率预估算 ...
- java poi技术读取到数据库
https://www.cnblogs.com/hongten/p/java_poi_excel.html java的poi技术读取Excel数据到MySQL 这篇blog是介绍java中的poi技术 ...
- c# 批量处理数据录入
c# 分批处理数据录入 //using System.Text; //using System.Data; //using System.Data.SqlClient; //using System; ...
- JavaScript闭包总结
闭包是你家庭中的第三者你在享受着第三者给你带来的便利时,而你的家庭也随时触发前所未有的危机(直男癌患者的观点);闭包是指有权访问另一个函数作用域中的变量的函数,创建闭包的常见的方式,就是在一个函数内部 ...
- 针对“来用”团队项目之NABC分析
本项目特点之一:扩展性强 NABC分析: N(need):我们这个开发的这个软件主要是集娱乐软件和实用工具于一身的大容器,这里面有很多应用程序,针对不同用户需要,至少有一款应用程序能够满足用户的需要, ...
- UVA 167 R-The Sultan's Successors
https://vjudge.net/contest/68264#problem/R The Sultan of Nubia has no children, so she has decided t ...
- vue服务端渲染简单入门实例
想到要学习vue-ssr的同学,自不必多说,一定是熟悉了vue,并且多多少少做过几个项目.然后学习vue服务端渲染无非解决首屏渲染的白屏问题以及SEO友好. 话不多说,笔者也是研究多日才搞明白这个服务 ...
- Java中关于 ArrayList 和 Map 的常用遍历方法 (学习笔记,便于以后查询)
一.学习ArrayList与Map时,关于常用遍历方法的记录如下: 二.附源码如下: package com.study.in.myself; import java.util.ArrayList; ...
- [剑指Offer] 47.求1+2+3+...+n
题目描述 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). [思路]用&&的短路思想来求和 ...