栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 3455 Cheesy Chess

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 3455 Cheesy Chess

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define N 100char map[10][10];int wx,wy,hx,hy;int visit[10][10][100];int dir[8][2]= {0,1,1,1,1,0,1,-1,0,-1,-1,-1,-1,0,-1,1};struct node{    int x;    int y;    int step;} a[N];bool judge(node a){    if(a.x==hx+a.step&&(a.y==hy+1||a.y==hy-1))return false;    if(map[a.x][a.y]=='F'||map[a.x][a.y]=='D')return false;    return a.x>=1&&a.y>=1&&a.x<=8&&a.y<=8&&!visit[a.x][a.y][a.step];}int bfs(){    memset(visit,0,sizeof(visit));    int front=0;    int rear=1;    node cur;    a[0].x=wx;    a[0].y=wy;    a[0].step=0;    visit[wx][wy][0]=1;    int flag=1;    int mm=0;    while(front<rear)    {        node cur;        cur.x=a[front].x;        cur.y=a[front].y;        cur.step=a[front].step;        //黑被挡住了,白win        if(map[hx+cur.step][hy]=='F')        { return 1;        }        //黑到底了,黑win        if(hx+cur.step>8)        { return 0;        }        for(int i=0; i<8; i++)        { int tx=cur.x+dir[i][0]; int ty=cur.y+dir[i][1]; int tstep=cur.step+1; node b; b.step=tstep; b.x=tx; b.y=ty; if((tx>=1 && tx<=8) && (ty>=1 && ty<=8)  && map[tx][ty]!='F' && map[tx][ty]!='D'  && visit[tx][ty][tstep]==0) {     if(!((tx==hx+tstep && ty==hy-1) || (tx==hx+tstep && ty==hy+1)))     {     visit[tx][ty][tstep]=1;     if(tx==hx+cur.step&&ty==hy||tx==hx+tstep&&ty==hy)     {         //黑被抓住||黑被白堵死而走投无路         return 1;     }     node tmp;     tmp.x=tx;     tmp.y=ty;     tmp.step=tstep;     a[rear++]=tmp; } }        }        front++;    }    return 0;}int main(){    int t;    scanf("%d",&t);    while(t--)    {        for(int i=1; i<=8; i++)        { scanf("%s",map[i]+1);        }        scanf("%d%d",&wx,&wy);        int xx=wx;        wx=9-wy;        wy=xx;        scanf("%d%d",&hx,&hy);        xx=hx;        hx=9-hy;        hy=xx;        int ans=bfs();        if(ans==1)        { printf("Whiten");        }        else printf("Blackn");    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375317.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号