Codeforces Round #191 (Div. 2) D
2013-07-19 22:37
337 查看
先全部B
搜索,每次回溯的时候先D后R,第一块不拆依旧为蓝色
搜索,每次回溯的时候先D后R,第一块不拆依旧为蓝色
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; struct node { int x,y; int val; char color; } step[5555555]; int n,m,ans; char mp[555][555]; bool v[555][555]; int mx[4] = {-1,1,0,0}; int my[4] = {0,0,1,-1}; bool in(int x,int y) { if(x >= 1 && x <= n && y >= 1 && y <= m) { return true; } else { return false; } } void dfs(int x, int y) { v[x][y] = 1; for(int i = 0 ; i < 4 ; i ++){ int a = x + mx[i]; int b = y + my[i]; if(in(a,b) && v[a][b] == 0 && mp[a][b] == 'B') { dfs(a,b); } } step[ans].x = x; step[ans].y = y; step[ans].color = 'D'; ans++; step[ans].x = x; step[ans].y = y; step[ans].color = 'R'; ans++; } int main() { scanf("%d%d",&n,&m); memset(v,0,sizeof(v)); for(int i = 1 ; i <= n ; i ++) { for(int j = 1 ; j <= m ; j ++) { cin>>mp[i][j]; } } ans = 0; for(int i = 1 ; i <= n ; i ++) { for(int j = 1 ; j <= m ; j ++) { if(mp[i][j] == '#') { continue; } step[ans].x = i; step[ans].y = j; step[ans].color = 'B'; mp[i][j] = 'B'; ans++; } } for(int i = 1 ; i <= n ; i ++){ for(int j = 1 ; j <= m ; j ++){ if(v[i][j] || mp[i][j] == '#') continue; v[i][j] = 1; for(int k = 0 ; k < 4 ; k ++) { int a = i + mx[k]; int b = j + my[k]; if(in(a,b) && v[a][b] == 0 && mp[a][b] != '#') { dfs(a,b); } } } } cout<<ans<<endl; for(int i = 0 ; i < ans ; i ++) { printf("%c %d %d\n",step[i].color,step[i].x,step[i].y); } return 0; }
相关文章推荐
- Codeforces Round #191 (Div. 2) ABCD
- Codeforces Round #191 (Div. 2) 解题报告
- Codeforces Round #191 (Div. 2) A. Flipping Game(简单)
- Codeforces Round #191 (Div. 2) 解题报告
- Codeforces Round #191 (Div. 2) D. Block Tower
- Codeforces Round #191 (Div. 2) C. Magic Five
- Codeforces Round #191 (Div. 2)---A. Flipping Game
- Codeforces Round #191 (Div. 2)
- Codeforces Round #191 (Div. 2)
- Codeforces Round #191 (Div. 2)-A. Flipping Game
- Codeforces Round #191 (Div. 2) E. Axis Walking (状态压缩+lowbit应用)
- Codeforces Round #191 (Div. 2) E题
- Codeforces Round #191 (Div. 2) C. Magic Five(数学,逆元取膜模板)
- Codeforces Round #222 (Div. 2)---A. Playing with Dice
- Codeforces Round #FF (Div. 2) A. DZY Loves Hash
- Codeforces Round #364 (Div. 2) B
- Codeforces Round #430 (Div. 2) D
- Codeforces Round #132 (Div. 2) D. Hot Days
- Codeforces Round #464 (Div. 2) C. Convenient For Everybody
- Hot Days Codeforces Round #132 (Div. 2) D(贪心)