2016 长春东北赛---Coconuts(离散化+DFS)
题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=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).
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.
2
1
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;
const int N=;
LL dx[N],dy[N];///表示每一格压缩的长度;
bool v[N][N];
int dir[][]={{,},{-,},{,},{,-}};
LL r,c;
int n; struct Node{
long long v,p;
int id;
}x[N],y[N]; bool cmp1(const Node s1,const Node s2){
return s1.v<s2.v;
}
bool cmp2(const Node s1,const Node s2){
return s1.id<s2.id;
} LL dfs(int sx,int sy)
{
LL sum=dx[sx]*dy[sy];
v[sx][sy]=true;
for(int i=;i<;i++){
int nx=sx+dir[i][];
int ny=sy+dir[i][];
if(nx>&&ny>&&nx<=r&&ny<=c)
if(!v[nx][ny]){
sum+=dfs(nx,ny);
}
}
return sum;
} int main()
{
int T,Case=;
cin>>T;
while(T--)
{
printf("Case #%d:\n",Case++);
scanf("%lld%lld%d",&r,&c,&n);
for(int i=;i<=n;i++)
{
scanf("%lld%lld",&x[i].v,&y[i].v);
x[i].id=i;
y[i].id=i;
}
sort(x+,x+n+,cmp1);
sort(y+,y+n+,cmp1);
x[n+].v=r; y[n+].v=c;
x[n+].id=y[n+].id=n+;
x[].v=y[].v=;
x[].id=y[].id=; int tot=;
dx[]=;
for(int i=;i<=n+;i++)
{
if(x[i].v==x[i-].v){
x[i].p=tot;
}
else if(x[i].v==x[i-].v+){
x[i].p=++tot;
dx[tot]=;
}
else {
x[i].p=tot+;
dx[tot+]=;
dx[tot+]=x[i].v-x[i-].v-;
tot+=;
}
}
r=tot;
tot=;
dy[]=;
for(int i=;i<=n+;i++)
{
if(y[i].v==y[i-].v){
y[i].p=tot;
}
else if(y[i].v==y[i-].v+){
y[i].p=++tot;
dy[tot]=;
}
else {
y[i].p=tot+;
dy[tot+]=;
dy[tot+]=y[i].v-y[i-].v-;
tot+=;
}
}
c=tot; memset(v,,sizeof(v));
sort(x+,x+n+,cmp2);
sort(y+,y+n+,cmp2);
for(int i=;i<=n;i++)
v[x[i].p][y[i].p]=true;
long long ans[N];
tot=;
for(LL i=;i<=r;i++)
for(LL j=;j<=c;j++)
if(!v[i][j])
ans[tot]=dfs(i,j),tot++;
sort(ans,ans+tot);
printf("%d\n",tot);
for(int i=;i<tot;i++)
printf("%lld%c",ans[i],(i+==tot)?'\n':' ');
}
return ;
}
2016 长春东北赛---Coconuts(离散化+DFS)的更多相关文章
- hdu 5925 Coconuts 离散化+dfs
Coconuts Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem ...
- 2016 大连网赛---Weak Pair(dfs+树状数组)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5877 Problem Description You are given a rooted ...
- 2016 CCPC 东北地区重现赛
1. 2016 CCPC 东北地区重现赛 2.总结:弱渣,只做出01.03.05水题 08 HDU5929 Basic Data Structure 模拟,双端队列 1.题意:模拟一个栈的操 ...
- 2015年ACM长春区域赛比赛感悟
距离长春区域赛结束已经4天了,是时候整理一下这次比赛的点点滴滴了. 也是在比赛前一周才得到通知要我参加长春区域赛,当时也是既兴奋又感到有很大的压力,毕竟我的第一场比赛就是区域赛水平,还是很有挑战性的. ...
- 2012年长春网络赛(hdu命题)
为迎接9月14号hdu命题的长春网络赛 ACM弱校的弱菜,苦逼的在机房(感谢有你)呻吟几声: 1.对于本次网络赛,本校一共6名正式队员,训练靠的是完全的自主学习意识 2.对于网络赛的群殴模式,想竞争现 ...
- HDU 5923 Prediction(2016 CCPC东北地区大学生程序设计竞赛 Problem B,并查集)
题目链接 2016 CCPC东北地区大学生程序设计竞赛 B题 题意 给定一个无向图和一棵树,树上的每个结点对应无向图中的一条边,现在给出$q$个询问, 每次选定树中的一个点集,然后真正被选上的是这 ...
- Aizu 0531 "Paint Color" (坐标离散化+DFS or BFS)
传送门 题目描述: 为了宣传信息竞赛,要在长方形的三合板上喷油漆来制作招牌. 三合板上不需要涂色的部分预先贴好了护板. 被护板隔开的区域要涂上不同的颜色,比如上图就应该涂上5种颜色. 请编写一个程序计 ...
- hdu4605 树状数组+离散化+dfs
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 4816 Bathysphere (2013长春现场赛D题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...
随机推荐
- 将不确定变为确定~transactionscope何时提升为分布式事务?(sql2005数据库解决提升到MSDTC的办法)
回到目录 对于transactionscope不了解的同学,可以看我的相关文章 第二十六回 将不确定变为确定~transactionscope何时提升为分布式事务? 第二十七回 将不确定变为确 ...
- Mybatis文档阅读笔记(明日继续更新...)
今天在编写mybatis的mapper.xml时,发现对sql的配置还不是很熟,有很多一坨一坨的东西,其实是可以抽取成服用的.不过良好的组织代码,还是更重要的.
- [数据库连接池二]Java数据库连接池--C3P0和JDNI.
前言:上一篇文章中讲了DBCP的用法以及实现原理, 这一篇再来说下C3P0和JDNI的用法. 1.1.C3P0数据源 C3P0是一个开源的JDBC连接池,它实现了数据源和JNDI绑定,支持JDBC3规 ...
- Atitit usbQb212 oo 面向对象封装的标准化与规范解决方案java c# php js
Atitit usbQb212 oo 面向对象封装的标准化与规范解决方案java c# php js 1.1. 封装性是面象对象编程中的三大特性之一 三个基本的特性:封装.继承与多态1 1.2. 魔 ...
- Linux初学 - head,tail,grep,sed,yum,find
head 查看文件头部 -n 指定查看行数 默认10行 tail 查看文件尾部 n 指定查看行数 默认10行 Grep 命令 用法大全 . 参数: -I :忽略大小写 -c :打印匹配的行数 -l : ...
- linux 学习 常用命令
以下命令是本人的CentOS6.5系统 一.linux个目录的作用 #linux个目录的作用 /bin 所有用户都可使用的命令 /sbin 超级用户(root)可以使用的命令 /boot 系统目录建 ...
- 关于js中sort()排序方法
第一次写这个,算是记录自己的学习前端的一点点的历程吧.今天在做一个图片的随机排序遇到了一个问题,部分截图如下 我用的是json格式存储数组,想通过排序实现img数组中的内容升序或是降序发现用sort自 ...
- Struts2第一个例子Hello World!
1.首先用eclipse新建一个动态web项目Struts2Demo1: (把Default output floder由build\classes改成WebContent\WEB-INF\class ...
- javase基础复习攻略《八》
进入第八篇,我们开始讨论JAVA的IO初步.在JAVA程序中,对数据的输入\输出操作以"流"(stream)方式进行,J2SDK提供了各种各样的"流"类,用于获 ...
- HTML Inspector – 帮助你编写高质量的 HTML 代码
HTML Inspector 是一款代码质量检测工具,帮助你编写更优秀的 HTML 代码.HTML Inspector 使用 JavaScript 编写,运行在浏览器中,是最好的 HTML 代码检测工 ...