Hexagonal Rooks 计蒜客(模拟)

本文探讨了六角棋盘上的特殊国际象棋变种——六角棋中车的移动方式。介绍了棋盘布局,车的移动规则,并提供了一个算法来计算从一个位置到另一个位置的可能移动路径数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值