您的位置:首页 > 其它

cf#328-A. PawnChess-水题

2015-11-01 13:24 267 查看
http://codeforces.com/contest/592/problem/A

给你8*8地图

问白子先到达对面还是黑子。。。只能往前走。。。

暴力算一下哪个离对面最近就好了。。。如果路上会碰到对方棋子就无法前进了。。

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
/*........
........
.B....W.
....W...
........
..W...B.
........
........*/
char tm[10][10];
int who[10];
int min(int a,int b)
{
return a<b?a:b;
}
int main()
{

int i,j,k;
int min_b=10000;
int min_w=10000;

for (i=1;i<=8;i++)
{
scanf("%s",tm[i]+1);
getchar();
}

for (i=1;i<=8;i++)
{
for (j=1;j<=8;j++)
{
if (tm[i][j]=='B')
{
int flag=0;
for (k=i+1;k<=8;k++)
{
if (tm[k][j]=='W')
{
flag=1;break;
}
}
if (flag==1) continue;
else
min_b=min(min_b,8-i);
}
else
if (tm[i][j]=='W')
{
int flag=0;
for (k=i-1;k>=1;k--)
{
if (tm[k][j]=='B')
{
flag=1;break;
}
}
if (flag==1) continue;
else
min_w=min(min_w,i-1);
}

}

}

if (min_b<min_w)
printf("B\n");
else
printf("A\n");

return 0;

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