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, ...
随机推荐
- react native 常用组件汇总
react-native-uploader //文件上传https://github.com/aroth/react-native-uploader jpush-react-native //官方版本 ...
- 对.Net Core结合Docker和Jexus的实践
本文基于上次尝试之后的进一步尝试,加入Docker容器.编写Dockerfile,并且jexus结合Docker的使用,总结下自己的个人感想. 一.环境介绍 当前的场景有两种方式将Demo实现运行,一 ...
- Redis集群分布
Redis系列 作者Mr.Chen,转载请注明博客出处:http://www.cnblogs.com/cjh-notes/ Redis集群存储 先看下架构图,下面说明其存储原理:首先redis每个节点 ...
- 📉 Draggable Curve Control (English)
Conmajia 2012 Updated on Feb. 18, 2018 In Photoshop, there is a very powerful feature called Curve A ...
- Tomcat服务器的配置
本地安装的Tomcat服务器版本是 Apache Tomcat/7.0.42 启动 localhost 使用Tomcat的前提是安装了jdk,我在本地安装了jdk7.Tomcat服务器的文件目录为F: ...
- 启动MySql提示:The server quit without updating PID file(…)失败
1.可能是/usr/local/mysql/data/rekfan.pid文件没有写的权限解决方法 :给予权限,执行 "chown -R mysql:mysql /var/data" ...
- 简单http文件服务器
日常工作中,主要是通过ssh终端(putty等)远程开发,经常涉及到传输文件,因为本地系统为Win10,所以没办法利用强大的linux脚本来进行文件传输.之前用过python的SimpleHttp模块 ...
- Mysql(二):库操作
一 系统数据库 information_schema: 虚拟库,不占用磁盘空间,存储的是数据库启动后的一些参数,如用户表信息.列信息.权限信息.字符信息等performance_schema: MyS ...
- SpringMVC+FreeMarker实现静态资源文件自动添加版本号(md5)
近日切换java开发,开始学习springframework.在实现静态资源文件自动计算版本号的实例时,因为不熟悉框架,走了不少弯路,好在最终解决了问题.这里写篇文章记录一下实现,也希望对大家有些用处 ...
- core java
ConsoleTest,这个程序如果在IDE里运行就会因无法获得控制台而报错 import java.io.Console; public class ConsoleTest { public sta ...