POJ 3765 Xiang Hex【暴力模拟】

Xiang Hex
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 985 Accepted: 509

Description

Xiang Hex is Chinese Chess played upon an elongated hexagonal field, consisting of nine files with the outer ones being seven cells and the center being eleven. The "palace" consists of seven cells, the first three cells of the center file and the first two cells which flank. The "river" is denoted by fourth cell of the first and ninth file, the fifth cell of the third and seventh file and the sixth cell of the center file. The player's side of the field consists of the cells before the "river".

If you know how to play Chess, the rules of Xiang Hex will be familiar. The general idea is the same. Each player controls an army (red or black) of pieces, moves one piece at a time, and tries to get the opponent's royal piece.

You can see the "palace" and the "river" below: ("r" is the "river", "P" is the "palace" of red army, and "p" is the "palace" of black army)


 

Each file was marked from the left to the right with an uppercase character A, B ... I, and the location of a hexagonal can be expressed by the character of the file and the number of hexagonal under it in the same file (No space between the character and the number).

There are seven kinds of pieces in Xiang Hex:

  1. SOLDIER(S) step one forward orthogonal before entering the "river". Upon and after entering the "river" step one forward, right forward or left forward orthogonal, or right or left diagonal.
  2. HORSE(H) step one vacant orthogonal then one diagonal in the same direction.
  3. CHARIOT(C) slide orthogonal.
  4. CANNON(A) slide orthogonal through vacant cells, may leap any one piece to capture an enemy.
  5. ELEPHANT(E) step two diagonal and never cross the "river".
  6. MANDARIN(M) step diagonal and never leave the "palace"
  7. GENERAL(G) step orthogonal and never leave the "palace". Not permitted be on an empty file with the opposing GENERAL.

And this is the setup of Xiang Hex: (Lowercase pieces belong to black army and uppercase pieces belong to red army)


The game is won by checkmating the opposing GENERAL. A player loses if stalemate or repetition of position. If both players have no pieces which can cross the "river", the game is drawn.

Recently, the Association of Chess Men (ACM) wants to hold a competition of Xiang Hex. However, they don't know how to display the current board in real-time during the games. Now they ask you for help.

Input

There are several test cases in the input. The first line of each case contains an integer n, the number of pieces on the board. The following n lines, each line contains the location of the pieces and a character indicates the type of the pieces. The input is ended by n = 0.

Output

Just display the board as the sample. Extra space at the end of line is not allowed.

Sample Input

11
E10 g
C8 e
E9 m
B6 C
I5 s
H5 a
D5 h
C4 S
A1 S
E1 G
H1 A
0

Sample Output

         _
       _/g\_
     _/ \_/ \_
   _/e\_/m\_/ \_
 _/ \_/ \_/ \_/ \_
/ \_/ \_/ \_/ \_/ \
\_/C\_/ \_/ \_/ \_/
/ \_/ \_/ \_/ \_/s\
\_/ \_/ \_/ \_/a\_/
/ \_/ \_/ \_/ \_/ \
\_/ \_/h\_/ \_/ \_/
/ \_/S\_/ \_/ \_/ \
\_/ \_/ \_/ \_/ \_/
/ \_/ \_/ \_/ \_/ \
\_/ \_/ \_/ \_/ \_/
/S\_/ \_/ \_/ \_/ \
\_/ \_/ \_/ \_/A\_/
/ \_/ \_/ \_/ \_/ \
\_/ \_/ \_/ \_/ \_/
  \_/ \_/G\_/ \_/
    \_/ \_/ \_/
      \_/ \_/
        \_/
 

题目大意:

给你一个蜂窝槽一样的一个基础图,然后在上边摆棋子,

思路:慢慢的,一步一步的,一点一点的,仔仔细细的,打图:

void init()
{
    memset(output,' ',sizeof(output));
        output[0][9]='_';
        output[1][8]='/';output[1][10]='\\';
        output[1][7]='_';output[1][11]='_';
        output[2][5]='_';output[2][6]='/';output[2][7]=' ';output[2][8]='\\';output[2][9]='_';output[2][10]='/';output[2][11]=' ';output[2][12]='\\';output[2][13]='_';
        output[3][3]='_';output[3][4]='/';output[3][5]=' ';output[3][6]='\\';output[3][7]='_';output[3][8]='/';output[3][9]=' ';output[3][10]='\\';output[3][11]='_';output[3][12]='/';output[3][13]=' ';output[3][14]='\\';output[3][15]='_';
        output[4][1]='_';output[4][2]='/';output[4][3]=' ';output[4][4]='\\';output[4][5]='_';output[4][6]='/';output[4][7]=' ';output[4][8]='\\';output[4][9]='_';output[4][10]='/';output[4][11]=' ';output[4][12]='\\';output[4][13]='_';output[4][14]='/';output[4][15]=' ';output[4][16]='\\';output[4][17]='_';
        output[5][0]='/';output[5][1]=' ';output[5][2]='\\';output[5][3]='_';output[5][4]='/';output[5][5]=' ';output[5][6]='\\';output[5][7]='_';output[5][8]='/';output[5][9]=' ';output[5][10]='\\';output[5][11]='_';output[5][12]='/';output[5][13]=' ';output[5][14]='\\';output[5][15]='_';output[5][16]='/';output[5][17]=' ';output[5][18]='\\';
        output[6][0]='\\';output[6][1]='_';output[6][2]='/';output[6][3]=' ';output[6][4]='\\';output[6][5]='_';output[6][6]='/';output[6][7]=' ';output[6][8]='\\';output[6][9]='_';output[6][10]='/';output[6][11]=' ';output[6][12]='\\';output[6][13]='_';output[6][14]='/';output[6][15]=' ';output[6][16]='\\';output[6][17]='_';output[6][18]='/';
        for(int i=7;i<=18;i++)
        {
            if(i%2==1)
            {
                for(int j=0;j<30;j++)
                {
                    output[i][j]=output[5][j];
                }
            }
            else
            {
                for(int j=0;j<30;j++)
                {
                    output[i][j]=output[6][j];
                }
            }
        }
        output[19][2]='\\';output[19][3]='_';output[19][4]='/';output[19][5]=' ';output[19][6]='\\';output[19][7]='_';output[19][8]='/';output[19][9]=' ';output[19][10]='\\';output[19][11]='_';output[19][12]='/';output[19][13]=' ';output[19][14]='\\';output[19][15]='_';output[19][16]='/';
        output[20][4]='\\';output[20][5]='_';output[20][6]='/';output[20][7]=' ';output[20][8]='\\';output[20][9]='_';output[20][10]='/';output[20][11]=' ';output[20][12]='\\';output[20][13]='_';output[20][14]='/';
        output[21][6]='\\';output[21][7]='_';output[21][8]='/';output[21][9]=' ';output[21][10]='\\';output[21][11]='_';output[21][12]='/';
        output[22][8]='\\';output[22][9]='_';output[22][10]='/';
}
然后分析当列是E的时候,当列是C/F的时候,当列是B/G的时候,当列是A/I的时候,行上边该确定的位子,和列上边控制的位子。

仔仔细细的判断完,我们就可以开开心心的AC啦~~~~~~~~~~

AC代码:

#include<stdio.h>
#include<string.h>
using namespace std;
char output[30][30];
void init()
{
    memset(output,' ',sizeof(output));
        output[0][9]='_';
        output[1][8]='/';output[1][10]='\\';
        output[1][7]='_';output[1][11]='_';
        output[2][5]='_';output[2][6]='/';output[2][7]=' ';output[2][8]='\\';output[2][9]='_';output[2][10]='/';output[2][11]=' ';output[2][12]='\\';output[2][13]='_';
        output[3][3]='_';output[3][4]='/';output[3][5]=' ';output[3][6]='\\';output[3][7]='_';output[3][8]='/';output[3][9]=' ';output[3][10]='\\';output[3][11]='_';output[3][12]='/';output[3][13]=' ';output[3][14]='\\';output[3][15]='_';
        output[4][1]='_';output[4][2]='/';output[4][3]=' ';output[4][4]='\\';output[4][5]='_';output[4][6]='/';output[4][7]=' ';output[4][8]='\\';output[4][9]='_';output[4][10]='/';output[4][11]=' ';output[4][12]='\\';output[4][13]='_';output[4][14]='/';output[4][15]=' ';output[4][16]='\\';output[4][17]='_';
        output[5][0]='/';output[5][1]=' ';output[5][2]='\\';output[5][3]='_';output[5][4]='/';output[5][5]=' ';output[5][6]='\\';output[5][7]='_';output[5][8]='/';output[5][9]=' ';output[5][10]='\\';output[5][11]='_';output[5][12]='/';output[5][13]=' ';output[5][14]='\\';output[5][15]='_';output[5][16]='/';output[5][17]=' ';output[5][18]='\\';
        output[6][0]='\\';output[6][1]='_';output[6][2]='/';output[6][3]=' ';output[6][4]='\\';output[6][5]='_';output[6][6]='/';output[6][7]=' ';output[6][8]='\\';output[6][9]='_';output[6][10]='/';output[6][11]=' ';output[6][12]='\\';output[6][13]='_';output[6][14]='/';output[6][15]=' ';output[6][16]='\\';output[6][17]='_';output[6][18]='/';
        for(int i=7;i<=18;i++)
        {
            if(i%2==1)
            {
                for(int j=0;j<30;j++)
                {
                    output[i][j]=output[5][j];
                }
            }
            else
            {
                for(int j=0;j<30;j++)
                {
                    output[i][j]=output[6][j];
                }
            }
        }
        output[19][2]='\\';output[19][3]='_';output[19][4]='/';output[19][5]=' ';output[19][6]='\\';output[19][7]='_';output[19][8]='/';output[19][9]=' ';output[19][10]='\\';output[19][11]='_';output[19][12]='/';output[19][13]=' ';output[19][14]='\\';output[19][15]='_';output[19][16]='/';
        output[20][4]='\\';output[20][5]='_';output[20][6]='/';output[20][7]=' ';output[20][8]='\\';output[20][9]='_';output[20][10]='/';output[20][11]=' ';output[20][12]='\\';output[20][13]='_';output[20][14]='/';
        output[21][6]='\\';output[21][7]='_';output[21][8]='/';output[21][9]=' ';output[21][10]='\\';output[21][11]='_';output[21][12]='/';
        output[22][8]='\\';output[22][9]='_';output[22][10]='/';
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if(n==0)break;
        init();
        for(int i=0;i<n;i++)
        {
            char str[15];char p;
            scanf("%s %c",str,&p);
            int lie=str[0]-'A'+1;
            int hang=0;
            int cont=1;
            for(int i=strlen(str)-1;i>=1;i--)
            {
                hang=cont*(str[i]-'0');
                cont*=10;
            }
            if(str[0]=='E')
            {
                hang=(10-hang)*2+1;
            }
            if(str[0]=='D'||str[0]=='F')
            {
                hang=(10-hang)*2;
            }
            if(str[0]=='C'||str[0]=='G')
            {
                hang=(9-hang)*2+1;
            }
            if(str[0]=='B'||str[0]=='H')
            {
                hang=(9-hang)*2;
            }
            if(str[0]=='A'||str[0]=='I')
            {
                hang=(8-hang)*2+1;
            }
            int zhenshilie=lie*2-1;
            output[hang][zhenshilie]=p;
            //printf("%d %d\n",zhenshilie-1,(10-hang)*2+1);
        }
        /*
      for(int i=0;i<23;i++)
      {
          for(int j=0;j<19;j++)
          {
              printf("%c",output[i][j]);
          }
          printf("\n");
      }*/
        for(int i=0;i<=4;i++)
        {
            for(int j=0;j<10+2*i;j++)
            {
                printf("%c",output[i][j]);
            }
            printf("\n");
        }
        for(int i=5;i<19;i++)
        {
            for(int j=0;j<19;j++)
            {
                printf("%c",output[i][j]);
            }
            printf("\n");
        }
        for(int i=19;i<=22;i++)
        {
            int tmp=i-19;
            for(int j=0;j<16-tmp*2+1;j++)
            {
                printf("%c",output[i][j]);
            }
            printf("\n");
        }
    }
}








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值