比完看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的更多相关文章

  1. 【BFS】【map】hdu5925 Coconuts

    题意:一张n*m的网格图(n和m可以达到10^9),其中K个点是障碍物(不超过200个),问你没有被障碍物占据的点形成了几个连通块?并且输出各个连通块的大小. 容易证明,大小超过40000的连通块最多 ...

  2. 2016 长春东北赛---Coconuts(离散化+DFS)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5925 Problem Description TanBig, a friend of Mr. Frog ...

  3. hdu 5925 Coconuts 离散化+dfs

    Coconuts Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem ...

  4. HDU 5925 Coconuts 【离散化+BFS】 (2016CCPC东北地区大学生程序设计竞赛)

    Coconuts Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  5. SPOJ Coconuts 最大流 最小割

    A group of n castle guards are voting to determine whether African swallows can carry coconuts. Whil ...

  6. Coconuts HDU - 5925 (二维离散化求连通块的个数以及大小)

    题目链接: D - Coconuts  HDU - 5925 题目大意:首先是T组测试样例,然后给你n*m的矩阵,原先矩阵里面都是白色的点,然后再输入k个黑色的点.这k个黑色的点可能会使得原先白色的点 ...

  7. Coconuts, Revisited(递推+枚举+模拟)

    Description The short story titled Coconuts, by Ben Ames Williams, appeared in the Saturday Evening ...

  8. HDU 5925 Coconuts 离散化

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5925 Coconuts Time Limit: 9000/4500 MS (Java/Others) ...

  9. Coconuts HDU - 5925 二维离散化 自闭了

    TanBig, a friend of Mr. Frog, likes eating very much, so he always has dreams about eating. One day, ...

随机推荐

  1. WebService的学习

    这篇文章不错,直接转了 http://blog.csdn.net/terryzero/article/details/5976638#comments

  2. BZOJ 2467: [中山市选2010]生成树 [组合计数]

    2467: [中山市选2010]生成树 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 638  Solved: 453[Submit][Status][ ...

  3. C++数据个数未知情况下的输入方法

    我们经常需要输入一串数,而数据个数未知.这时候就不能以数据个数作为输入是否结束的判断标准了. 这种情况下,我们可以用以下两种方法输入数据. 方法一:判断回车键(用getchar()=='\n'即可判断 ...

  4. 二、urllib进阶

    Handler处理器 和 自定义Opener opener是 urllib.request.OpenerDirector 的实例,我们之前一直都在使用的urlopen,它是一个特殊的opener(也就 ...

  5. 关于字符型char变量

    写程序时,意外发现个很不容易察觉问题出在哪的问题的 scanf("%c",&ch); scanf("%c",&c); printf(" ...

  6. Java经典编程题50道之三十九

    写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度. public class Example39 {    public static void main(String[] a ...

  7. ubuntu16.04编译安装mysql-boost-5.7.21并编译成php扩展测试与使用

    我之前的文章已经改造了自定义MVC框架中的工具类(验证码,图片上传,图像处理,分类)4个类,接下来,就要改造模型类,模型类肯定要连接数据库,由于我的Ubuntu Linux是裸装的php(目前只编译了 ...

  8. Eclipse中如何忽略报错的js文件

    https://jingyan.baidu.com/article/4f7d5712d3701a1a20192786.html

  9. Centos6增加新用户并赋予权限

    第一步:创建用户并设置密码 useradd testuser // 增加用户名为'testuser'的用户 passwd testpasswd //设定密码为'testpasswd' 第二步:用户授权 ...

  10. PAT1078 Hashing 坑爹

    思路:用筛法给素数打表,二次探测法(只需要增加的)–如果的位置被占,那么就依次探测. 注意:如果输入的,这也不是素数:如果,你需要打表的范围就更大了,因为不是素数. AC代码 #include < ...