Hexagonal Rooks 計蒜客(模擬)

Hexagonal Rooks 計蒜客 - 43472

It is game night and Alice and Bob are playing chess. After beating Bob at chess several times, Alice suggests they should play a chess variant instead called hexagonal chess. Although the game is very rarely played nowadays, Alice knows the rules very well and has obtained a hexagonal chess board from her subscription to the magazine of Bizarre Artifacts for Playing Chess.

在這裏插入圖片描述

Figure H.1: The field naming of the hexagonal chess board and the directions in which a rook can move.

The hexagonal chess board, shown above, consists of 91 hexagonal cells arranged in the shapeof a hexagon with side length 6 as depicted in the above diagrams. The board is divided into11 columns, each called a file, and the files are labeled a to k from left to right. It is also divided into 11 v-shaped rows, each called a rank, which are labeled 1 to 11 from bottom to top. The unique cell in file x and rank y is then denoted by the coordinate xy. For example, rank 11 contains only a single cell f11 and rank 7 is occupied entirely by the black player’s pawns.

Alice begins by explaining how all the pieces move. The simplest piece is the rook, which can move an arbitrary positive number of steps in a straight line in the direction of any of its 6 adjacent cells, as depicted in the figure on the right. Bob immediately realises that the hexagonal rook already is more difficult to work with than its regular chess counterpart.

In order to attack one of the opponents pieces, it is useful to know which cells his rook can move to such that it attacks the opposing piece. The more of these cells there are, the more valuable the current position of his rook is. However, calculating this number is too much for Bob. After losing so many games of regular chess, Alice allows Bob to use a program to assist in his rook placement. While Alice explains the rest of the game you get busy coding.

As a small simplification, Bob will compute the number of ways his rook can move to the destination cell assuming there are no other pieces on the board, not even the piece he wants to attack.

Input :

• The input consists of one line, containing two different coordinates on the hexagonal chess board, the current positions of your rook and the piece you want to attack.

Output:

Output a single integer, the number of ways the rook can move from its current position to the position of the piece it wants to attack in exactly two moves, assuming there are no other pieces on the board.

樣例輸入
c4 h4
樣例輸出
6

題意:一個棋盤,字母代表列,數字代表一個V型對應的行,棋子可以延六邊形的六個方向的任意一個方向做任意長度的直線運動,給兩個點,求棋子從一個點到另一個點,走且僅走兩步,有幾種方法可以到達;

  • 找出兩個位置一步可到達的點,取交集
  • 上下方向可到達的好判斷,在同一列的都是
  • 左上到右下:每個列的行座標相對大小 6,6,6,6,6,6,5,4,3,2,1
  • 左下到右上:每個列的行座標相對大小 1,2,3,4,5,6,6,6,6,6,6
  • 交集的大小就是結果
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;

int maxn[] = {0,6,7,8,9,10,11,10,9,8,7,6};
int left_down[]= {0,1,2,3,4,5,6,6,6,6,6,6};
int left_up[] = {0,6,6,6,6,6,6,5,4,3,2,1};
int tail1 = -1;
int tail2 = -1;
int ans = 0;

struct node
{
    int x;
    int y;
} a[1200],b[1200];

bool cmp(node a,node b)
{
    if(a.x==b.x)
        return a.y<b.y;
    return a.x<b.x;
}

void count_(int x,int y,node *a,int &tail)
{
    for(int i = 1; i<=maxn[x]; i++)
    {
        if(i==y)
            continue;
        a[++tail].x = x;
        a[tail].y = i;
    }
    for(int i = 1; i<=11; i++)
    {
        if(i==x)
            continue;
        int yy = y+left_up[i]-left_up[x];
        if(yy>=1&&yy<=maxn[i])
        {
            a[++tail].x = i;
            a[tail].y = yy;
        }
    }
    for(int i = 1; i<=11; i++)
    {
        if(i==x)
            continue;
        int yy = y+left_down[i]-left_down[x];
        if(yy>=1&&yy<=maxn[i])
        {
            a[++tail].x = i;
            a[tail].y = yy;
        }
    }
}
void find_equal()
{
    int i = 0,j = 0;
    while(i<=tail1&&j<=tail2)
    {
        if(a[i].x==b[j].x&&a[i].y==b[j].y)
        {
            //printf("%d %d\n",a[i].x,a[i].y);
            ans++;
            i++;
            j++;
        }
        else if(cmp(a[i],b[j])==0)
            j++;
        else
            i++;
    }
}
//void output(node a[],int tail)
//{
//    for(int i = 0;i<=tail;i++)
//    {
//        printf("|%d %d| ",a[i].x,a[i].y);
//    }
//    cout<<endl;
//}
int main()
{
    char s1[5],s2[5];
    int word1,dig1,word2,dig2;
    cin>>s1>>s2;

    word1 = s1[0]-'a'+1;
    dig1 = strlen(s1)==3?10:s1[1]-'0';
    if(s1[2]=='1')
        dig1++;
    word2 = s2[0]-'a'+1;
    dig2 = strlen(s2)==3?10:s2[1]-'0';
    if(s2[2]=='1')
        dig2++;

    count_(word1,dig1,a,tail1);
    count_(word2,dig2,b,tail2);
    sort(a,a+tail1+1,cmp);
    sort(b,b+tail2+1,cmp);
    // output(a,tail1);
    // output(b,tail2);
    find_equal();
    // if(strcmp(s1,s2)==0)
    //   ans++;
    cout<<ans<<endl;


}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章