CodeForces Round #292 Div.2
2015-02-18 14:46
260 查看
昨天注册了没有打,晚上给长辈们敬完酒,回来就洗洗睡了,=_=||
A. Drazil and Date
题意:
是否有可能恰好用s步,从原点走到(a, b)。
分析:
首先要走到终点至少要|a|+|b|步,如果还剩多余的步数的话,那就向右走一格再走回来。
也就是s要比|a|+|b|多偶数步(包括0)才可以。
代码君
A. Drazil and Date
题意:
是否有可能恰好用s步,从原点走到(a, b)。
分析:
首先要走到终点至少要|a|+|b|步,如果还剩多余的步数的话,那就向右走一格再走回来。
也就是s要比|a|+|b|多偶数步(包括0)才可以。
#include <bits/stdc++.h> #define PII pair<int,int> #define MP make_pair #define F first #define S second using namespace std; const int maxn = 2000 + 10; char s[maxn][maxn]; int deg[maxn][maxn]; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; char fillchar[2][5] = { "^<v>", "v>^<" }; inline int caldeg(int i, int j)//计算该点的度数 { return (int)(s[i-1][j] == '.') + (int)(s[i+1][j] == '.') + (int)(s[i][j-1] == '.') + (int)(s[i][j+1] == '.'); } int main() { //freopen("in.txt", "r", stdin); int n, m; scanf("%d%d", &n, &m); for(int i = 1; i <= n; ++i) scanf("%s", s[i]+1); queue<PII> Q; int cnt = 0; for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) if(s[i][j] == '.') { deg[i][j] = caldeg(i, j); cnt++; if(deg[i][j] == 1) Q.push(MP(i, j)); } if(cnt & 1) { puts("Not unique"); return 0; } while(!Q.empty()) { PII cur = Q.front(); Q.pop(); int x = cur.F; int y = cur.S; if(s[x][y] == '.') { int i, nx, ny; for(i = 0; i < 4; ++i) { nx = x + dx[i]; ny = y + dy[i]; if(s[nx][ny] == '.') break; } if(i == 4) { puts("Not unique"); return 0; } s[x][y] = fillchar[0][i];//放砖块 s[nx][ny] = fillchar[1][i]; deg[x][y] = deg[nx][ny] = 0; cnt -= 2; for(i = 0; i < 4; ++i) { int nnx = nx + dx[i]; int nny = ny + dy[i]; if(s[nnx][nny] == '.') { deg[nnx][nny]--;//更新周围点的度数 if(deg[nnx][nny] == 1) Q.push(MP(nnx, nny)); } } } } if(cnt != 0) puts("Not unique");//还存在空位置 else for(int i = 1; i <= n; ++i) printf("%s\n", s[i]+1); return 0; }
代码君
相关文章推荐
- CodeForces Round #294 Div.2
- CodeForces Round #295 Div.2
- Codeforces Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) 部分题解
- codeforces Round#158 Div.2 C
- Code forces Round #292 div2
- Codeforces Round #212 (Div.2)
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)
- codeforces Round 314 div.2
- Codeforces Round 465 div.2 C&D
- Codeforces Round #292 (Div. 2)C,D拓扑排序
- Codeforces Round #FF (Div.2 )(C,D)
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)
- codeforces Round#158 Div.2 小结
- Codeforces Round #285 (Div.1 B & Div.2 D) Misha and Permutations Summation --二分+树状数组
- Codeforces Round #292
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)
- codeforces Round #Pi (div.2) 567ABCD
- Codeforces Round #455 Div.2 909A
- Codeforces Round #410 (Div.2) C.Mike and gcd problem-数学
- Codeforces Round 190 div.2 322C 321A Ciel and Robot