2017CCSP-01 Backgammon simple simulation

Title and surface data

For each blank, define a variable cnt = 0, represents the number of variations of five children, four search directions on both sides after the space is filled, provided for each direction of the continuous pieces are white \ (WA \) , \ (WB \) , the following situations.

  • \ (wa> = 5 \ & \ & wb> = 5 \) after fill in the blank cnt--
  • \ (wa, wb \) is only equal to a greater than 5, cnt unchanged after fill in the blank
  • \ (wa, wb \) is less than 5, and \ (WA + WB> =. 4 \) , fill in the blank after cnt ++

After four directions are determined, if cnt> = 0, so the point can be output.

Out of a small error

while (the inband (Ti, tj) to true && == A [Ti] [tj] = 'W')
Ti and tj there may be negative, then the subscript access error occurs, the determination may not be placed while loop.

int dx[]={1,1,0,1};
int dy[]={1,0,1,-1};
int n;
bool inband(int x,int y)
{
    return x>=0&&y>=0&&x<=n-1&&y<=n-1;
}
string a[45];

int ans[2000];
int cur=0;
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(a[i][j]!='*')continue;
            int cnt=0;
            for(int k=0;k<=3;k++)
            {
                int wa=0,wb=0;
                int ti=i+dx[k];
                int tj=j+dy[k];
                while(inband(ti,tj)==true)
                {

                    if(a[ti][tj]!='w')break;///panduan
                    wa++;
                    ti+=dx[k];
                    tj+=dy[k];
                }
                ti=i-dx[k];
                tj=j-dy[k];

                while(inband(ti,tj)==true)
                {
                    if(a[ti][tj]!='w')break;
                    wb++;
                    ti-=dx[k];
                    tj-=dy[k];
                }
                if(wa>=5&&wb>=5)
                {
                    cnt--;
                    continue;
                }
                if(wa>=5||wb>=5)
                {
                    continue;
                }
                else if(wa+wb>=4)
                {
                    cnt++;
                }
            }
            if(cnt>0)
            {
                printf("%d %d\n",j,i);
            }
        }
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/Tony100K/p/11622165.html