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, ...
随机推荐
- 一次saltstack环境变量的坑
现场环境: salt-minion端: ip:10.0.3.149 环境:使用 nvm装的nodejs 受用nodejs自带的npm 安装pm2 sal-master端: IP:10.0 ...
- apache配置详解
可参考:Apache 的 httpd.conf 详解 ServerTokens OS 此指令控制了Server回送给客户端的回应头域是否包含关于服务器OS类型和编译进的模块描述信息.服务器会发送:Se ...
- java中的各种Queue
java中的各种并发Queue可以归为以下的几种: ConcurrentLinkedQueue: 一个由链表结构组成的非阻塞队列 ArrayBlockingQueue :一个由数组结构组成的有界阻塞队 ...
- WPF 圆角输入框
今天打算来做一个圆角的输入框 默认输入框: 这个输入框不好看,并且在XP 跟 WIN 7 WIN10 效果 都不太一样 我们今天不用模板的方式,而是 最简单的方式 来实现 圆角 输入框: ----- ...
- 机器学习实践之Logistic回归
关于本文说明,本人原博客地址位于http://blog.csdn.net/qq_37608890,本文来自笔者于2017年12月17日 19:18:31所撰写内容(http://blog.cs ...
- qt 移植到开发板
一.准备工作: 1.QT应用程序 2.工具链--->交叉工具链一安装,就会有标准的c库 3.扩展的第三方库(ARM)()触摸屏库(tslib.tar.gz) 4.QT库 二.使用交叉工具链编译t ...
- shared_lock and unique_lock
简单的说: shared_lock是read lock.被锁后仍允许其他线程执行同样被shared_lock的代码.这是一般做读操作时的需要. unique_lock是write lock.被锁后不允 ...
- ubuntu14.04上实现faster rcnn_TF的demo程序及训练过程
安装环境:Ubuntu14.04.显卡Tesla K40C+GeForce GT 705.tensorflow1.0.0.pycharm5.0 说明:原文见博客园,有问题原文下留言,不定期回复.本文作 ...
- 基于Centos7的autobahn-python+crossbar的环境搭建
一.基于centos7的crossbar安装(已经安装好python) (1) sudo yum update (2) sudo yum install gcc gcc-c++ make openss ...
- Ubuntu16.04下的NetCore环境搭建
跨平台系列汇总:http://www.cnblogs.com/dunitian/p/4822808.html#linux VSCode安装:http://www.cnblogs.com/dunitia ...