codeforces 327D Block Tower
2013-07-07 22:02
253 查看
题目见http://codeforces.com/problemset/problem/327/D
分析见http://codeforces.com/blog/entry/8274
憋了一个小时终于把它给搞出来了,T_T
分析见http://codeforces.com/blog/entry/8274
憋了一个小时终于把它给搞出来了,T_T
#include <vector> #include <list> #include <limits.h> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <string.h> #include <stdlib.h> using namespace std; const int dir_x[] = {0, 0, -1, 1}; const int dir_y[] = {1, -1, 0, 0}; int main(){ int row, col; string board[505]; int flag[505][505]; int step = 0; vector<pair<int, int> > v; vector<int> typ; cin>>row>>col; for(int i=0; i<row; i++) cin>>board[i]; memset(flag, 0, sizeof(flag)); queue<pair<int, int> > q; vector<pair<char, pair<int, int> > > res; for(int i=0; i<row; i++) for(int j=0; j<col; j++){ if(board[i][j]=='#' || flag[i][j]!=0) continue; flag[i][j] = 1; while(q.empty() == false) q.pop(); v.clear(); typ.clear(); q.push(make_pair(i, j)); v.push_back(make_pair(i, j)); typ.push_back(1); int number = 1; while(q.empty()==false){ number++; pair<int, int> cur = q.front(); q.pop(); int x=cur.first, y=cur.second; for(int k=0; k<4; k++){ int tmpx = x+dir_x[k]; int tmpy = y+dir_y[k]; if(tmpx<0 || tmpx>=row || tmpy<0 || tmpy>=col) continue; if(flag[tmpx][tmpy]!=0 || board[tmpx][tmpy]=='#') continue; flag[tmpx][tmpy] = number; q.push(make_pair(tmpx, tmpy)); v.push_back(make_pair(tmpx, tmpy)); typ.push_back(number); } //number++; } int len = v.size(); for(int k=0; k<len; k++){ res.push_back(make_pair('B', make_pair(v[k].first, v[k].second))); step++; } for(int k=len-1; k>0; k--){ res.push_back(make_pair('D', make_pair(v[k].first, v[k].second))); res.push_back(make_pair('R', make_pair(v[k].first, v[k].second))); step += 2; } } cout<<step<<endl; for(int i=0; i<step; i++){ cout<<res[i].first<<" "<<res[i].second.first+1<<" "<<res[i].second.second+1<<endl; } //system("pause"); return 0; }
相关文章推荐
- CodeForces - 327D Block Tower (dfs)
- Codeforces 327D Block Tower【思维+Bfs】
- Codeforces 327D Block Tower【BFS+优先队列】
- codeforces 327D. Block Tower(高级DFS)
- CodeForces 327D Block Tower(DFS)
- CF 327D - Block Tower 数学题 DFS 初看很难,想通了就感觉很简单
- cf 327D Block Tower
- CF 327D -Block Tower
- D. Block Tower (CF 327D 搜索)
- CF 327D - Block Tower 数学题 DFS 初看很难,想通了就感觉很简单
- Codeforces 463C Gargari and Bishops(贪心)
- codeforces 380D. Sereja and Cinema(#223div1 组合数学)
- CodeForces 605E Intergalaxy Trips (概率)
- Codeforces 309B
- CodeForces 831A-Unimodal Array
- CodeForces - 847A Union of Doubly Linked Lists
- Codeforces 463D. Gargari and Permutations【DP】
- Codeforces 601A The Two Routes(暴力)
- CodeForces - 569A Music
- 【Codeforces 631 B Print Check 】+ 简单构造