hdu5925 Coconuts
比完看acdream说这题是签到题 怎么都不会写
我现在补完也觉得 这不是傻逼题么
我我这个这么快5题的人真的不应该啊
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(X) ((int)X.size())
const int MAXN = 505;
const int INF = 0x3f3f3f3f;
int R,C,n;
int dir[][4] = { {1,0}, {-1,0}, {0,-1}, {0,1} };
int X[MAXN], Y[MAXN];
int has[MAXN]; int pos[MAXN]; int tot;
int v1[MAXN]; int vx;
int v2[MAXN]; int vy;
vector<ll> Ans;
int vis[MAXN][MAXN];
void bfs(int x,int y) {
// printf("%d %d\n",x,y);
queue<pair<int,int>> Q;
Q.push({x,y}); vis[x][y] = 1;
ll ans = 0;
while(!Q.empty()) {
int t1 = Q.front().first; int t2 = Q.front().second; Q.pop();
ans += 1ll*v1[t1]*v2[t2];
for(int i = 0; i < 4; ++i) {
int xx = t1+dir[i][0]; int yy = t2+dir[i][1];
if(xx >= 1 && xx <= vx && yy >= 1 && yy <= vy && !vis[xx][yy]) {
vis[xx][yy] = 1;
Q.push({xx,yy});
}
}
}
Ans.push_back(ans);
}
int main(){
int _; scanf("%d",&_);
for(int cas=1;cas<=_;cas++) {
Ans.clear();
memset(vis,0,sizeof(vis));
scanf("%d %d %d",&R,&C,&n);
for(int i = 0; i < n; ++i) {
scanf("%d %d",&X[i],&Y[i]);
}
tot = 0;
for(int i = 0; i < n; ++i) {
has[tot++] = X[i];
}
sort(has,has+tot);
tot = unique(has,has+tot) - has;
int pre = 0; vx = 0;
for(int i = 0; i < tot; ++i) {
if(pre+1 < has[i]) v1[++vx] = has[i]-pre-1;
v1[++vx] = 1; pos[i] = vx;
pre = has[i];
}
if(has[tot-1] < R) v1[++vx] = R-has[n-1];
for(int i = 0; i < n; ++i) {
int tt = lower_bound(has,has+tot,X[i]) - has;
X[i] = pos[tt];
}
tot = 0;
for(int i = 0; i < n; ++i) {
has[tot++] = Y[i];
}
sort(has,has+tot);
tot = unique(has,has+tot) - has;
pre = 0; vy = 0;
for(int i = 0; i < tot; ++i) {
if(pre+1 < has[i]) v2[++vy] = has[i]-pre-1;
v2[++vy] = 1; pos[i] = vy;
pre = has[i];
}
if(has[tot-1] < C) v2[++vy] = C-has[n-1];
for(int i = 0; i < n; ++i) {
int tt = lower_bound(has,has+tot,Y[i]) - has;
Y[i] = pos[tt];
}
for(int i = 0; i < n; ++i) {
vis[X[i]][Y[i]] = 1;
}
// printf("hh\n");
for(int i = 1; i <= vx; ++i)
for(int j = 1; j <= vy; ++j) {
if(!vis[i][j]) {
bfs(i,j);
}
}
// for(int i = 1; i <= vx; ++i) printf("%d ",v1[i]); printf("\n");
// for(int i = 1; i <= vy; ++i) printf("%d ",v2[i]); printf("\n");
// for(int i = 0; i < n; ++i) printf("%d %d\n",X[i],Y[i]);
sort(Ans.begin(), Ans.end());
printf("Case #%d:\n%d\n",cas,sz(Ans));
for(int i = 0; i < sz(Ans); ++i) {
if(i) printf(" ");
printf("%lld",Ans[i]);
} printf("\n");
}
return 0;
}
hdu5925 Coconuts的更多相关文章
- 【BFS】【map】hdu5925 Coconuts
题意:一张n*m的网格图(n和m可以达到10^9),其中K个点是障碍物(不超过200个),问你没有被障碍物占据的点形成了几个连通块?并且输出各个连通块的大小. 容易证明,大小超过40000的连通块最多 ...
- 2016 长春东北赛---Coconuts(离散化+DFS)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5925 Problem Description TanBig, a friend of Mr. Frog ...
- hdu 5925 Coconuts 离散化+dfs
Coconuts Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem ...
- HDU 5925 Coconuts 【离散化+BFS】 (2016CCPC东北地区大学生程序设计竞赛)
Coconuts Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- SPOJ Coconuts 最大流 最小割
A group of n castle guards are voting to determine whether African swallows can carry coconuts. Whil ...
- Coconuts HDU - 5925 (二维离散化求连通块的个数以及大小)
题目链接: D - Coconuts HDU - 5925 题目大意:首先是T组测试样例,然后给你n*m的矩阵,原先矩阵里面都是白色的点,然后再输入k个黑色的点.这k个黑色的点可能会使得原先白色的点 ...
- Coconuts, Revisited(递推+枚举+模拟)
Description The short story titled Coconuts, by Ben Ames Williams, appeared in the Saturday Evening ...
- HDU 5925 Coconuts 离散化
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5925 Coconuts Time Limit: 9000/4500 MS (Java/Others) ...
- Coconuts HDU - 5925 二维离散化 自闭了
TanBig, a friend of Mr. Frog, likes eating very much, so he always has dreams about eating. One day, ...
随机推荐
- jboss7.1.1相关error及解决办法
问题1: 报错提示: 公司的网站系统使用的中间是jboss7.1.1 Final,由于有些数据和服务测试环境不具备,免不了要在测试环境调试些jsp页面,发现从jboss社区里下载的jboss应用有个问 ...
- 数组的复制及ES6数组的扩展
一.数组的复制 // alert([1,2,3]==[1,2,3]); let cc = [0,1,2]; let dd = cc; alert(dd==cc);//此时改变dd会影响cc ES5 只 ...
- Java流机制学习
基本概念 BaseStream 基础流是一个可行并行或者串行的汇聚操作的元素序列.可以进行顺序遍历,也可以进行并发遍历.通过它也可以得到一个并行流或者串行流. Stream 是Java中流的表现接口, ...
- 关于ES6 用箭头函数后的 this 指向问题
最近写完小程序后, 开始学习React, 因为有编译器, 就直接用ES6 新语法了, 中间自然离不开 () => { console.log('箭头函数的this是指向哪的问题')}; var ...
- 01 Mybatis 的配置和使用
一.Mybatis 是什么 MyBatis 是一个支持普通SQL查询.存储过程和高级映射的优秀持久层框架.MyBatis 消除了几乎所有的 JDBC 代码和参数的手工设置以及对结果集的检索封装.MyB ...
- python 3.x 爬虫基础---Urllib详解
python 3.x 爬虫基础 python 3.x 爬虫基础---http headers详解 python 3.x 爬虫基础---Urllib详解 前言 爬虫也了解了一段时间了希望在半个月的时间内 ...
- 阿里云学习之IOT物联网套件(配置篇)
文档时间:2018.-1-24 首注:此文章是参照以下文章的整合与补充: https://bbs.aliyun.com/read/309106.html?amp;displayMode=1&p ...
- [Python Study Notes]CS架构远程访问获取信息--Client端v2.0
更新内容: 1.增加内存信息获取 2.增加电池信息获取 3.增加磁盘信息获取 4.重新布局窗体 5.增加窗体名称 6.增加连接成功之前,不可按压 效果图: '''''''''''''''''''''' ...
- Java Integer类型比较
今天做了一道题目题目如下: Integer a=10; Integer b=10; System.out.print(a==b); Integer c=200; Integer d=200; Syst ...
- HDU - 2181 dfs [kuangbin带你飞]专题二
保存每个节点的下一个节点一直往下面走就行了,不能重复经过某个点,当经过的点达到20个而且当前节点的下一个节点是起点就打印答案. AC代码 #include<cstdio> #include ...