CodeForces616C The Labyrinth
来源:互联网 发布:普通话测试软件 编辑:程序博客网 时间:2024/05/22 03:47
The original problem is in this page
https://vjudge.net/problem/306223/origin
And let’s skip to the point. The is a DFS problem and considered that the number could be very large,this time I mark every reachable blocks with same numbers if they’re adjacent.Only if I realize the mistakes I’ve made can I make something different.
#include <iostream>#include<queue>#include<cstring>#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;int dx[4]={0,0,1,-1};int dy[4]={1,-1,0,0};int N,M;char m[1005][1005];int vis[1005][1005];int c[1005][1005];int area[1005*1005];int cnt;void dfs(int x,int y){ vis[x][y]=1; c[x][y]=cnt; area[cnt]++; for(int i=0;i<4;i++) { int xx=x+dx[i]; int yy=y+dy[i]; if(xx>=0&&yy>=0&&xx<N&&yy<M&&!vis[xx][yy]&&m[xx][yy]=='.') { dfs(xx,yy); } }}int main(){ cin>>N>>M; for(int i=0;i<N;i++) { for(int j=0;j<M;j++) { cin>>m[i][j]; } } for(int i=0;i<N;i++) { for(int j=0;j<M;j++) { if(m[i][j]=='.'&&vis[i][j]==0) { cnt++; dfs(i,j); } } } for(int i=0;i<N;i++) { for(int j=0;j<M;j++) { if(m[i][j]=='.') { cout<<"."; } else { int ans,x,y; int d[5]; for (int k = 0; k < 4; k++) { x = i + dx[k], y = j + dy[k]; d[k] = c[x][y]; } sort(d, d + 4); ans = 1 + area[d[0]]; for (int k = 1; k < 4; k++) { if (d[k] != d[k - 1]) {ans += area[d[k]];} } cout<<ans%10; } } cout<<endl; } return 0;}
0 0
- Codeforces616C The Labyrinth
- CodeForces616C The Labyrinth
- codeforces616C The Labyrinth
- The Labyrinth (dfs)
- codeforces_616C. The Labyrinth
- Codeforces 616C The Labyrinth
- codeforces 616C The Labyrinth
- Codeforces 616C The Labyrinth
- The Labyrinth CodeForces - 616C
- The Labyrinth 联通分量+搜索
- Labyrinth
- Labyrinth
- Labyrinth
- Labyrinth
- 3808: Neerc2012 Labyrinth of the Minotaur
- URAL - 1145 Rope in the Labyrinth
- codeforces 616C The Labyrinth(bfs)
- CF 616C The Labyrinth(dfs)
- HNOI 2008 GT考试
- POJ-3461-Oulipo KMP
- Python学习--18 进程和线程
- 每天一个linux命令:du 命令
- web前端14
- CodeForces616C The Labyrinth
- Words of Life
- poj 1039 Pipe
- Static与non Static
- 基于NIOS-II的示波器:PART1 按键&显示屏驱动&界面
- GCD
- 特朗普违反外交礼仪
- web前端15
- OnTouchListener与OnGestureListener的区别