求助!
查看原帖
求助!
701254
Mu_leaf楼主2023/8/10 10:47

rt.

我设出了两种行进方式需要的步数(以下称为 aa 和 bb)

我解出的解是 a=(2×y−x)/3a=(2\times y-x)/3 和 b=(2×x−y)b=(2\times x-y)。

我不是太明白为什么这个解为什么会有 1 个点 WA,1 个点 TLE,而题解的不会。

且我想知道是怎么解出 x−(x+y)/3x-(x+y)/3 和 y−(x+y)/3y-(x+y)/3 的。

#include <bits/stdc++.h>
#define int unsigned long long
using namespace std;
const int N=5e6+6,mod=1e9+7;
int x,y;
int inv[N];
//C[n][m]=C(n,m)
inline int read()
{
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c>'9')
    {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        x = (x << 3) + (x << 1) + (c ^ '0');
        c = getchar();
    }
    return x * f;
}
int P(int a,int b){
	int ans=1,now=a;
	while(b){
		if(b&1){
			ans=(ans*now)%mod;
		}now=(now*now)%mod;
		b>>=1;
	}return ans;
}
signed main(){
	x = read();
    y = read();
	if((x+y)%3!=0){
		printf("0\n");
		return 0;
	}
	int a=(2*y-x)/3,b=(2*x-y)/3;
	int ans=1;
	for(int i=1;i<=b;i++){
		ans=(ans*(a+i)%mod*P(i,mod-2)%mod)%mod;
	}
	cout << ans;
	return 0;
}
//0 0
//1 2
//2 1
//C(n,m)=n!/(m!*(n-m)!)
//C(4,2)=4!/(2!*2!)=6
/*
设a是上2右1的步数-
  b是上1右2的步数
  4a+2b=2y
  a+2b=x
  a+b=(x+y)/3
  a-b=y-x 
  2a=(x+y)/3+y-x
  
  a=(2x-y)/3;
  b=(2y-x)/3
*/ 
2023/8/10 10:47
加载中...