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, ...
随机推荐
- CTSC 2017 滚粗记
CTSC 2017 滚粗记 结束好几天了一直没写. 明天就要去参加二轮省选了,填一下坑吧. 所以可能很多东西已经忘了 Day -2 [5.5 Fri] 周五晚上是其他学信竞的同学来机房的时间... 也 ...
- CF 291E. Tree-String Problem [dfs kmp trie图优化]
CF291E 题意:一棵树,每条边上有一些字符,求目标串出现了多少次 直接求目标串的fail然后一边dfs一边跑kmp 然后就被特殊数据卡到\(O(n^2)\)了... 因为这样kmp复杂度分析的基础 ...
- Go终端读写
终端读写 操作终端相关文件句柄常量 os.Stdin:标准输入 os.Stdout:标准输出 os.Stderr:标准错误输出 终端读写实例: package main import ( " ...
- JDBC【PreparedStatment、批处理、处理二进制、自动主键、调用存储过程、函数】
1.PreparedStatement对象 PreparedStatement对象继承Statement对象,它比Statement对象更强大,使用起来更简单 Statement对象编译SQL语句时, ...
- vue调试工具之 vue-devtools的安装
这里介绍一下vue-devtools的安装方法之一: chrome浏览器的应用商店不能直接访问(需要跨域),所以直接应用商店安装的方法就行不通了. 1.到github主页去下载安装: git clon ...
- 用java代码发送http请求
//发送post请求 PrintWriter out = null; BufferedReader in = null; String result = ""; try { URL ...
- yum 安装 nfs,rpcbind 出现错误 libc.so.6(GLIBC_2.14)(64bit) is needed by
错误信息: Running rpm_check_debugERROR with rpm_check_debug vs depsolve:libc.so.6(GLIBC_2.14)(64bit) is ...
- Nginx调用远程php-fpm
在Nginx服务器的情况下,当我们输入 http://localhost:8080/index.php回车的时候 浏览器会将请求发送给Nginx,Nginx会根据我们所配置的以.php结尾的PHP的文 ...
- HashMap、Hashtable、 LinkedHashMap、TreeMap四者之分。
java为数据结构中的映射定义了一个接口java.util.Map,此接口主要有四个常用的实现类,分别是HasMap.Hashtable.LinkedHasmap和TreeMap. (1)HashMa ...
- appium+Python 启动app(二)
我们上步操作基本完成,下面介绍编写Python脚本启动app 打开我们pycharm新建.py文件 第一步:输入Python脚本代码: #coding=utf-8 from appium import ...