NOJ [1187] Hole Breaker
来源:互联网 发布:matlab读取字符串数组 编辑:程序博客网 时间:2024/05/18 01:40
- 问题描述
- XadillaX wants a big hole to store some *&@#(*&@!#(*&!)(@&#^& things. So he bought a Hole Breaker.
The ground is an N * N square. The breaker will break a 1 * 1 square hole in the ground per second.
XadillaX is so excited that he can't wait any more. After the breaker worked for several seconds, he will calculate out the maximum hole area. - 输入
- This problem contains several cases.
The first line of each case contains two integers N and M, indicate the side of ground and the number of operations. (N <= 3 <= 1000, 1 <= M <= 200000).
Then follow M lines.
Each line is a command:
B x y: Break a hole at (x, y). You can assume that every coordinate will at most break for once.
C : Calculate out the maximum area of the holes and output. (Two holes are connected when they share an edge) - 输出
- For each 'C' command, output the maximum area of the holes.
这题就是并查集,二维当一维来做,苦逼的我查错查了很久....
#include<stdio.h>#include<string.h>int father[1001000];int rank[1001000];bool is_break[1001000];int n,ans;int find(int x){if(x==father[x]) return father[x];else{ father[x]=find(father[x]); return father[x];} }void Union(int x1,int x2){int p1=find(x1);int p2=find(x2);if(p1!=p2){father[p2]=p1;rank[p1]+=rank[p2];if(rank[p1]>ans) ans=rank[p1]; return ;}}int main(){int m;while(~scanf("%d%d",&n,&m)){int i,j;int x,y;char op[5];ans=0;for(i=0;i<n*n;i++){father[i]=i;rank[i]=1;} int z;memset(is_break,0,sizeof(is_break));int is_not=0;for(i=1;i<=m;i++){scanf("%s",op);if(op[0]=='B'){scanf("%d%d",&x,&y); is_not=1; if(x!=0) z=x*n+y; else z=y; is_break[z]=1;if( x!=0 && is_break[z-n]==1) Union(z,z-n); if(x!=n-1 && is_break[z+n]==1) Union(z,z+n); if(y!=0 && is_break[z-1]==1) Union(z,z-1); if(y!=n-1 && is_break[z+1]==1) Union(z,z+1);}else if(op[0]=='C'){if(ans==0 && is_not==1) printf("1\n"); elseprintf("%d\n",ans);} }}return 0;}
0 0
- NOJ [1187] Hole Breaker
- NBOJ 1187 Hole Breaker 并查集
- NOJ [1301] Gopher Hole
- NOJ [1301] Gopher Hole
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1187&&Hole Breaker
- NOJ [1320] Hole of Black
- Hole
- NOJ 1301 Gopher Hole 并查集好题 n*n矩阵上打洞 不相连洞的个数
- Noj
- pump, breaker, etc.
- 伤得起 screen breaker
- Word Breaker II
- Circuit Breaker模式
- SpringBoot -- 熔断机制 Circuit Breaker
- Another hole...
- Watering Hole
- NOJ 176
- NOJ 175
- 第一次写博客
- .net读取注册表
- Linux服务器架设---NAT服务器设置
- alert和confirm相关
- V9摄影美学三亚国际公馆2013年11月正式登陆三亚,同年12盛大开幕!
- NOJ [1187] Hole Breaker
- 俄罗斯方块c/c++语言代码
- 我的第一篇CSDN播客
- 北京哪些医院不用特意选择就可用社保卡直接就医?
- renderscript
- 使用DBMS_JOB包创建ORACLE定时任务
- DP合集
- 软考 -> 网络中各种交换设备
- 剑指offer:栈的压力、弹出序列