[2019HDU second field correction Multi] [HDU 6591] [A. Another Chess Problem]

Topic links: http://acm.hdu.edu.cn/showproblem.php?pid=6591

Subject to the effect: two-dimensional coordinate system, all meet \ (5 | 2x + y \) points have been set obstacles, can not pass. Are now given a pair of points, one of which come from the Q least one point to another mobile number and corresponding program number (per unit length may be moved a)

Solution: First, out of the picture, so long

    All the figures can not be traveled is represented by the red dot. It can be found ( this is the Bagua backgammon) lattice points of these figures is divided into several small pieces (Fig block indicated by blue), four in each patch between every two points to ensure distance will not be affected by red dot. So we can consider the point where the block association, the movement between point conversion between the mobile computing block answer.

   I In this problem each block is below a red dot point corresponding to the block, and the point \ ((2,1) \) as the \ new coordinates ((1,0) \) to transforming the coordinate system, whereas in the block, each block may be provided for the upper left corner point \ (0 \), set successively clockwise \ (1,2,3 \) is calculated in the same after such a convenient the answer to move.

   Upon completion of conversion coordinates for the movement between the blocks can be seen as seeking to move I \ (n-\) line, \ (m \) Number of program. Since this \ (n, m \) may be negative, so that they can be considered to do after all converted to positive numbers, there are many methods of conversion, a method wherein: first judgment \ (n-\) is positive or negative, if negative start and end points can be exchanged, so that the answer is the same, after the determination \ (m \) is positive or negative if it is negative can be a symmetric transformation, the \ (m \) to a positive number, here to note point position is also within the block may change.

   Then we find that if we continuously moved in one direction, the number of steps to move will be more than in alternate directions, so we want to minimize the number of continuously to the same direction of movement, the least number of times can be calculated, assuming it is \ (t \), then the program will multiply the number \ (2 ^ t \), because when a continuous one direction to go, we must walk within a block diagonal, so every time there will be two to go law. In addition to which point we have to consider the number of programs to change the direction of movement in different locations, this can be used to calculate the number of combinations, then we only need to enumerate the starting point from which point blocks and reach the finish block .

 

#include<bits/stdc++.h>
using namespace std;
#define N 200001
#define LL long long
#define MOD 998244353
int T,n,m,ans,num,f[N],p[N],q[N],dis[4][4];
struct Point
{
    int x,y,o;
    void read(){scanf("%d%d",&x,&y);}
    void get()
      {
      int tmp=((2*x+y)%5+5)%5;
      if(tmp==2)o=0,y-=2;
      else if(tmp==4)o=1,x--,y-=2;
      else if(tmp==3)o=2,x--,y--;
      else if(tmp==1)o=3,y--;
      else while(true);
      int tmpx=(2*x+y)/5,tmpy=(2*y-x)/5;
      x=tmpx,y=tmpy;
      }
}A,B;
void pretype()
{
    f[1]=2;
    p[1]=q[1]=1;
    f[0]=p[0]=q[0]=1;
    for(int i=2;i<N;i++)
      {
      f[i]=2ll*f[i-1]%MOD;
      p[i]=1ll*p[i-1]*i%MOD;
      q[i]=1ll*(MOD-MOD/i)*q[MOD%i]%MOD;
      }
    for(int i=2;i<N;i++)
      q[i]=1ll*q[i-1]*q[i]%MOD;
    for(int i=0;i<4;i++)
      for(int j=0;j<4;j++)
        dis[i][j]=min(abs(i-j),4-abs(i-j));
}
int C(int n,int m){return 1ll*p[n]*q[m]%MOD*q[n-m]%MOD;}
void rua(int o1,int o2,int n,int m)
{
    int w[2]={n,m}; 
    int res=0,tot=1,t;
    if(w[o1]<1 || w[o2]<1)return;
    if(o1==o2 && w[o1]<2 && n+m>1)return;
    res=(n+m)*2-1;
    if(n+m>1)
      {
      w[o1]--,w[o2]--;
      if(o1==o2)
        {
        t=abs(w[o1]+1-w[o1^1]);
        res+=t,tot=f[t];
        if(w[o1]+1>=w[o1^1])
          tot=1ll*tot*C(w[o1]+1,w[o1^1])%MOD;
        else tot=1ll*tot*C(w[o1^1]-1,w[o1])%MOD;
        }
      else
        {
        t=abs(w[o1]-w[o2]);
        res+=t,tot=f[t];
        if(w[o1]>=w[o2])
          all1ll * all * = C (w [w1] w [o2])% MOD;
        else all 1ll * all * = C (w [o2] w [w1])% MOD; 
        } 
      } 
    T = dis [w1] [Ao]; 
    nothing + = t; if (t> 1 ) all 2ll * =% all MOD; 
    t = dis [o2 + 2 ] [Bo]; 
    nothing + = t; if (t> 1 ) all 2ll * =% all MOD;
    if (res == years) num = (num + all)% MOD;
    if (res <ans) ans = nothing num = all; 
} 
Int main () 
{ 
    pretype (); 
    scanf ( " % d",&T);
    while(T--)
      {
      A.read(),A.get();
      B.read(),B.get();
      n=B.y-A.y,m=B.x-A.x;
      if(n==0 && m==0)
        {
        ans=dis[A.o][B.o];
        num=ans>1?2:1;
        printf("%d %d\n",ans,num);
        continue;
        }
      if(n<0 || (n==0 && m<0))
        swap(A,B),n=-n,m=-m;
      if(m<0)A.o=(4-A.o)%4,B.o=(4-B.o)%4,m=-m;
      ans=19260817,num=0;
      for(int i=0;i<2;i++)
        for(int j=2;j<4;j++)
          rua(i,j-2,n,m);
      printf("%d %d\n",ans,num);
      }
}
View Code

 

Guess you like

Origin www.cnblogs.com/DeaphetS/p/11290348.html