比完看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. hdu5925 Coconuts(坐标离散化)

    题目 r*c(0<r,c<=1e9)的网格图,有n(0<=n<=200)个障碍点不能被访问,其余点是连通的, 输出这张网格图上的连通块的数量,按增序输出每个连通块的大小 思路来 ...

  2. SP1693 COCONUTS - 题解

    SP1693 COCONUTS 题意: 几个士兵在投票,有支持与反对两种选择,每个人有自己的看法,但是他们有时也会为了支持朋友的看法而放弃自己的看法,请求出一种方案,使得违背自己初始看法的人数与看法不 ...

  3. 【斜率优化】Codechef July Challenge 2019——Hit the Coconuts

    前言 能够自己推出斜率优化的式子了...实属难得... 不过定义和实现都是参考了别人的博客的,╮(╯▽╰)╭... woc...写博客的时候发现自己推的式子的变量有点问题.../难受 题目 All s ...

  4. HDU - 5925 D - Coconuts

    D - Coconuts 题 意:给你一个R*C的矩阵,有K堵墙,问你有几个联通快,每个联通块的元素是多少? 数据范围: 1<=R,C<=1e9 0<=k<=200 输入样例: ...

  5. HDU 1346(Coconuts, Revisited)

    暴力破解即可,从 n-1 开始枚举人数,最先找到的满足要求的人数即为最大人数. #include <iostream> using namespace std;int main() {in ...

  6. SPOJ 1693 Coconuts

    SPOJ_1693 COCONUTS 对于每个人的选择一共有两种,根据他们最后的选择就可以将这些人分成两个集合,显然集合间如果有朋友形成的边的话是要删掉的,这样实际上就形成了一个割,对应的持不同意见的 ...

  7. UVa 616 - Coconuts, Revisited (数学)

    题意 第一个人平分椰子,然后取一堆,正好剩下一个给猴子.以此类推.到第二天正好分给所有人,问人最多有几个. 思路 我们可以枚举n-1的因子,再逐一检查是否符合条件. 代码 #include <s ...

  8. 【暴力+模拟】HDU-1346 Coconuts, Revisited

    注解 1.暴力模拟,从题目给定的数目减一开始枚举人数,直到人数只有1人为止.最先找到的满足题目要求的人数,就是答案. 代码 #include <iostream>using namespa ...

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

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

最新文章

  1. 三极管的发射极与集电极之间的关系
  2. 监听服务端口及邮件报警脚本
  3. 百信银行基于 Apache Hudi 实时数据湖演进方案
  4. VC 2010下安装OpenCV2.4.4
  5. OC如何跳到系统设置里的各种设置界面
  6. Intelli IDEA 快捷键操作,咱来点不一样的
  7. 最长递增子序列LIS再谈
  8. 数据库外键名称不要用自动生成的名字
  9. 互联网光环下的新金融群像:运营最重要的是说人话
  10. linux cups打印中文,Linux使用cups进行打印
  11. 2018杭州云栖大会,梁胜博士的演讲PPT来啦! 1
  12. SpringBoot + Spring Cloud +Vue 管理系统前端搭建(二、visual studio code开发前端项目
  13. 易语言魔兽世界怀旧服自动钓鱼源码
  14. COINDAO将迎来首次回购分红,COINDAO白名单和团队长参与方式。
  15. 五、软考·系统架构师——系统分析
  16. XDOJ 字符串压缩 C
  17. U8出纳管理:删除“银行日记账”中一条银行流水时,提示如图所示
  18. 第二次上机实践项目-项目4-穷举法-换分币
  19. HTML期末大作业 : 个人网页制作 大学生个人网页设计 个人网站模板 简单静态HTML个人网页作品...
  20. 完美java.util.zip使用,实现zip压缩和解压

热门文章

  1. Matplotlib图形绘制
  2. 利用3DMax整理UE5模型材质卡槽
  3. DHL测试新包裹站,只需要一个App
  4. JavaScript内置对象 之 Math数学对象
  5. Keycloak概述
  6. k8s copy命令使用
  7. Java Servlet 中的 ServletConfig 和 ServletContext 之间的区别
  8. 本地音乐播放器各种BUG Android10(HUAWEI手机)
  9. c语言中1e18怎么控制条件,C语言复习之实验五
  10. QT qt 3d 绘图