A. 2:40:11(-7) solved by zcz

通过旋转使得抓人的在左下角,逃得在右上角

结论是逃得一定在右上 或者 右下 左上被抓住,找到规律枚举一下即可

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
long long n,m;
void change(long long &x,long long &y)
{
    long long t=x;
    x=m+1-y;
    y=t;
}
const int now_size = 3;
const int mod = 1025436931;
class Matix
{
  public:
    LL mdata[3][3];

    Matix(int value = 0)
    {
        memset(mdata, 0, sizeof(mdata));
        if (value == 1)
        {
            for (int i = 0; i < now_size; i++)
                mdata[i][i] = 1;
        }
    }
    Matix(const Matix &s1)
    {
        for (int i = 0; i < now_size; i++)
        {
            for (int j = 0; j < now_size; j++)
            {
                mdata[i][j] = s1.mdata[i][j];
            }
        }
    }
    Matix operator * (const Matix &s1)
    {
        Matix ans;
        for (int i=0; i<now_size; i++)
        {
            for (int j=0; j<now_size; j++)
            {
                for (int k=0; k<now_size; k++)
                {
                    ans.mdata[i][j] = (ans.mdata[i][j] + mdata[i][k]* s1.mdata[k][j])%mod;
                }
            }
        }

        return ans;
    }
};

LL fbnq(LL k)
{
    Matix p1;
    p1.mdata[0][0] = 1;
    p1.mdata[0][1] = 1;
    p1.mdata[0][2] = 1;
    p1.mdata[1][1] = 1;
    p1.mdata[1][2] = 1;
    p1.mdata[2][1] = 1;
    Matix ans(1);
    k--;
    while (k)
    {
        if (k&1)
            ans = ans *p1;
        p1 = p1*p1;
        k>>=1;
    }
    LL fans = (ans.mdata[0][0] + ans.mdata[0][1]) % mod;
    return fans;
}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        long long x1,x2,y1,y2;
        cin>>n>>m>>x1>>y1>>x2>>y2;
        if(n==1&&m==1)
        {
            cout<<"countless"<<endl;
            continue;
        }
        if(x1==x2&&y1==y2)
        {
            cout<<0<<endl;
            continue;
        }
        while(!(x1<x2&&y1<=y2))
        {
            change(x1,y1);
            change(x2,y2);
            swap(n,m);
        }
        if(m==1)
        {
            if((x2-x1)%2==0)
            {
                cout<<fbnq(n-x1-1)<<endl;
            }
            else
            {
                cout<<fbnq(n-x1)<<endl;
            }
            continue;
        }
        if((x2-x1+y2-y1)%2==1)
        {
            cout<<"countless"<<endl;
            continue;
        }
        long long ans=n-x1+m-y1;
        if(x2-x1>y2-y1)
        {
            ans=max(ans,n-x1+y1-1);
        }
        if(x2-x1<y2-y1)
        {
            ans=max(ans,m-y1+x1-1);
        }
        cout<<fbnq(ans-1)<<endl;
    }


    return 0;
}
A

相关文章:

  • 2022-12-23
  • 2021-10-09
  • 2022-12-23
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-13
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
相关资源
相似解决方案