您的位置:首页 > 其它

CodeForces Round #292 Div.2

2015-02-18 14:46 260 查看
昨天注册了没有打,晚上给长辈们敬完酒,回来就洗洗睡了,=_=||

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;
}


代码君
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: