[IOI1994]The Castle
来源:互联网 发布:深入浅出的数据分析 编辑:程序博客网 时间:2024/05/21 21:42
开了博客之后一直没动今天水完题手痒想起这个就来水一篇陈年水题(雾
题目链接<<
- 题意:给一张n*m个格子的地图信息,求连通块个数以及最大连通块面积.
- 每个格子四个方向可以有墙,输入用一个十进制数表示.
把每个格子的数字展开成二进制后就表示各方向上是否有墙.
直接用结构体存每个格子,读入的时候顺便处理一下.
然后直接bfs就好啦…(QwQ我一开始写判断的时候偷懒省了大括号成功的挂掉…
然后贴一下代码(QwQ跟别人比好像写的特别长…
#include<cstdio>#include<queue>using namespace std;const int N=55;struct point{bool w[4];}map[N][N];struct p{int x,y;};typedef queue<p> Queue;int n,m,tmp,ans,num;int dx[]={0,-1,0,1};int dy[]={-1,0,1,0};bool vis[N][N];Queue Q;inline int max(int x,int y){return x>y?x:y;} inline void decom(int x,int y,int s){ for(int i=0;i<4;i++)map[x][y].w[i]=s&1,s>>=1;}inline bool ok(int x1,int y1,int x,int y,int id){ if(vis[x][y])return 0; if(x<1||y<1||x>n||y>m)return 0; if(id==0){if(map[x1][y1].w[0]||map[x][y].w[2])return 0;} else if(id==1){if(map[x1][y1].w[1]||map[x][y].w[3])return 0;} else if(id==2){if(map[x1][y1].w[2]||map[x][y].w[0])return 0;} else if(id==3){if(map[x1][y1].w[3]||map[x][y].w[1])return 0;} return 1;}inline void bfs(int x,int y){ if(vis[x][y])return; int temp=1;vis[x][y]=1;num++; Q.push((p){x,y}); while(!Q.empty()) { p t;t=Q.front();Q.pop(); for(int i=0;i<4;i++) { int tx=t.x+dx[i];int ty=t.y+dy[i]; if(ok(t.x,t.y,tx,ty,i)) { vis[tx][ty]=1;temp++; Q.push((p){tx,ty}); } } }ans=max(ans,temp);}int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)scanf("%d",&tmp),decom(i,j,tmp); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)bfs(i,j); printf("%d\n%d",num,ans); return 0;}
阅读全文
0 0
- [IOI1994]The Castle
- [IOI1994]The Castle
- 【IOI1994】The Clocks
- The Castle
- The Castle
- the castle
- The Castle
- The Castle
- The Castle
- The Castle
- The Castle
- USACO 2.1 The Castle (castle)
- USACO2.1.1 The Castle (castle)
- USACO2.1.1 The Castle (castle)
- 【图论】【USACO】The Castle
- 2.1.2 The Castle
- Section 2.1 The Castle
- 2.1The Castle
- 栈(Stack)的C语言实现
- spring-boot-笔记-2-thymeleaf初步了解
- 即时搜索的input和propertychange方法
- 如何从思维模式上彻底改变学习模式?
- Pacemaker
- [IOI1994]The Castle
- [编程题] 度度熊回家
- Java程序实现欧几里得算法-计算两个数的最大公约数
- 匈牙利算法
- 跳转传参,butterknife,xrecyclerview监听,刷新加载综合
- 字符串问题---替换字符串中连续出现的指定字符串
- JAVA垃圾回收机制概要
- 【贪心例题专题】&贪心~越多越好哟~&
- 整合Struts,Spring,mybatis三个框架的helloworld