hdu 5546 Ancient Go

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

 題目串連:  http://acm.hdu.edu.cn/showproblem.php?pid=5546

   題意: 有兩個人在一個9*9的棋盤裡下棋,A 是的棋子為x , B為 o  ,“.”  的意思為空白。 問 A的下一個 能否將 B 的棋子殺死, (跟圍棋差不多)。

解題大意: dfs  判聯通塊的周圍是否只有 一個 ‘ . ’. 

#include <iostream>#include<cstdio>#include<cstring>using namespace std;char Map[20][20];int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}},visit[20][20],ans,ant;void dfs(int x,int y){    int tx,ty,i;    visit[x][y]=ans;    for(i=0; i<4; i++)    {        tx=x+dir[i][0];        ty=y+dir[i][1];        if(Map[tx][ty]=='x')            continue;        if(tx<0||tx>=9||ty<0||ty>=9||visit[tx][ty]==ans)            continue;        if(Map[tx][ty]=='.')        {            ant++;            visit[tx][ty]=ans;        }        else        {            dfs(tx,ty);        }    }}int fuck(){    int i,j;    ans=0;    for(i=0; i<9; i++)    {        for(j=0; j<9; j++)        {            if(Map[i][j]=='o'&&!visit[i][j])            {                ans++;                ant=0;                dfs(i,j);                if(ant==1)                    return 1;            }        }    }    return 0;}int main(){    int t,i,k;    //freopen("in.txt","r",stdin);    //freopen("out.txt","w",stdout);    scanf("%d",&t);    k=1;    getchar();    while(t--)    {        memset(visit,0,sizeof(visit));        for(i=0; i<9; i++)        {            scanf("%s",Map[i]);        }        printf("Case #%d: ",k++);        if(fuck())            printf("Can kill in one move!!!\n");        else            printf("Can not kill in one move!!!\n");    }    return 0;}

感覺稍微吊一些的 dfs 。(模板)  * - * 。

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.