题目链接:https://codeforces.com/contest/31/problem/D

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
using namespace std;#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lowbit(x) (x & (-x))
#define CASET int _; scanf("%d", &_); for(int kase=1;kase<=_;kase++)typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;static const int INF=0x3f3f3f3f;
static const ll INFL=0x3f3f3f3f3f3f3f3f;
static const db EPS=1e-10;
static const db PI=acos(-1.0);
static const int MOD=1e9+7;template <typename T>
inline void read(T &f) {f = 0; T fu = 1; char c = getchar();while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }f *= fu;
}
template <typename T>
void print(T x) {if (x < 0) putchar('-'), x = -x;if (x < 10) putchar(x + 48);else print(x / 10), putchar(x % 10 + 48);
}
static const int MAXN=100*100+10;
bool d[MAXN][MAXN];
int n,m,t;
bool vis[MAXN];
vector<int> ans;
int main()
{read(m); read(n); read(t);while(t--){int x0,x1,y0,y1;read(y0);read(x0);  read(y1);read(x1); if(x0==x1){if(y0>y1) swap(y0,y1);for(int i=y0;i<y1;i++)if(x0) d[(x0-1)*m+i][x0*m+i]=d[x0*m+i][(x0-1)*m+i]=true;}else{if(x0>x1) swap(x0,x1);for(int i=x0;i<x1;i++)if(y0) d[i*m+y0-1][i*m+y0]=d[i*m+y0][i*m+y0-1]=true;}}for(int i=0;i<n;i++)for(int j=0;j<m;j++)if(!vis[i*m+j]){queue<int> Q;Q.push(i*m+j);vis[i*m+j]=true;int cnt=0;while(!Q.empty()){int u=Q.front();Q.pop();int x=u/m,y=u%m;cnt++;if(x+1<n && !vis[(x+1)*m+y] && !d[u][(x+1)*m+y]){Q.push((x+1)*m+y);vis[(x+1)*m+y]=true;}if(y+1<m && !vis[x*m+y+1] && !d[u][x*m+y+1]){Q.push(x*m+y+1);vis[x*m+y+1]=true;}}ans.push_back(cnt);}sort(ans.begin(),ans.end());for(int i=0;i<ans.size();i++)printf("%d ",ans[i]);return 0;
}

CodeForces - 31D Chocolate【几何】【连通块】相关推荐

  1. C. Edgy Trees Codeforces Round #548 (Div. 2) 【连通块】

    一.题面 here 二.分析 这题刚开始没读懂题意,后来明白了,原来就是一个数连通块里点数的问题.首先在建图的时候,只考虑红色路径上的点.为什么呢,因为为了不走红色的快,那么我们可以反着想只走红色的路 ...

  2. 【Codeforces Round #548(Div. 2)】Edgy Trees(数学+bfs求连通块)

    题目链接 C. Edgy Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Rumor CodeForces - 893C(并查集基本操作:维护连通块最值)

    题目链接 PS:这题也可以用dfs搜连通块,一遍搜一遍记录连通块的最值. AC代码: #include <iostream> #include <cstring> #inclu ...

  4. [C] [编程题]连通块(DFS解决)

    时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 256M,其他语言512M 来源:牛客网 金山办公2020校招服务端开发工程师笔试题(一) 题目描述 给一个01矩阵,1代表是陆地,0代表 ...

  5. [C] 深度优先搜索解决连通块/染色问题——求岛的个数

    本文介绍用DFS解决连通块个数问题 有关dfs的介绍见另外一篇:不撞南墙不回头--深度优先搜索 例题 宝岛探险 题目描述 一个小岛由一个主岛和一些复附属岛屿组成,该岛使用一个二维矩阵表示,其中数字表示 ...

  6. 树形dp ---- gym101655 D - Delta Quadrant 树上连通块思维换根 + 树形dp

    题目链接 题目大意: 给你一颗NNN个节点的树,树上每条边有边权就是遍历的时间,你可以从任意节点出发遍历N−kN-kN−k个点并且回到出发点,问你最短的时间是多少? k∈[0,min(N,20)],N ...

  7. UVa572 Oil Deposits DFS求连通块

    技巧:遍历8个方向 for(int dr = -1; dr <= 1; dr++)for(int dc = -1; dc <= 1; dc++)if(dr != 0 || dc != 0) ...

  8. DFS求连通块数目(深搜)

    DFS求连通块数目 这里认为,连通块是包括斜对角线的路径连通的块. 测试数据 5 5 ****@ *@@*@ *@**@ @@@*@ @@**@ 计算通过@相连的连通块的个数 测试输出: 2 样例代码 ...

  9. 求连通块个数(使用并查集)

    并查集求连通块个数的模板 #include<bits/stdc++.h>using namespace std;const int maxn = 1e5+5; vector<int& ...

最新文章

  1. linux /etc/hosts.allow和/etc/hosts.deny 限制 禁止 ip连接 黑名单 白名单
  2. 3、Oracle表空间管理
  3. NET快速信息化系统开发框架 V3.2 - “用户管理”主界面使用多表头展示、增加打印功能...
  4. 阿里云Maven镜像配置
  5. 分析Java核心转储
  6. 拳王虚拟项目公社:闲鱼操作卖资源如何赚钱?闲鱼怎么卖虚拟资源?卖什么资源赚钱?
  7. PHP支付宝手机网站支付功能
  8. 转载:世上最全的百物妙用窍门-绝对不能错过,不断更新中
  9. Java线程状态与方法关系
  10. 办公室电脑里的文件和家里电脑的文件同步,有什么便签软件可以实现
  11. 许鹏:从零开始学习,Apache Spark源码走读(一)
  12. 医院计算机考核制度,医院信息科考核内容标准细则
  13. 使用Zack.EventBus 对rabbitMQ简化操作
  14. Linux系统下利用共享内存模拟迅雷下载
  15. Viruses!!!!!
  16. OCR中文文字识别软件
  17. 【SAP】进项税的配置与传输
  18. 非托管内存转换为System.Drawing.Bitmap
  19. 浙大翁恺老师C语言教程自学笔录-计算机和编程语言
  20. 行列式求值Java语言实现———线性代数

热门文章

  1. 高考英语真题网络计算机话题,2019高考英语十大热门话题
  2. 原来装电信宽带送的光猫现在升级到了200M了是否要换个光猫?
  3. 关于评价指标的理解(TPR,FPR,TAR,FAR,FRR,ERR)
  4. nyoj171聪明的kk
  5. 炫龙笔记本安装Ubantu系统
  6. R语言使用多个数据类型不同的向量数据创建一个dataframe数据对象、使用$操作符和列名称访问dataframe指定数据列的数据
  7. 数据可视化:8款小众但好用的可视化工具
  8. 艾美捷细胞糖酵解分析试剂盒,基于比色法来检测
  9. 图像工程的读书笔记 图像成像过程
  10. 短路的原因与危害有哪些