BZOJ 2299 向量(裴蜀定理)

时间:2024-11-10 12:38:08

题意:给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), (-b,a), (-b,-a)这些向量,问你能不能拼出另一个向量(x,y)。

实际上前四个向量能拼出(ma,nb)(m%2=n%2).后四个向量拼出(xb,ya)(x%2=y%2).

这样可以枚举这四个未知数在模二意义下的解。这两个向量相加为(ma+xb,nb+ya).

对于ma+xb=X.根据系数的奇偶性,如果有系数为奇数,可使得等式两边都减去一个数使得系数都为偶数,这样再同除以二。

就是一般的用裴蜀定理来判断这类方程是否有解的过程了。

# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
const int N=;
//Code begin...
bool check(LL x, LL y, LL gcd){return x%gcd==&&y%gcd==;}
int main ()
{
int T;
LL a, b, x, y, gcd;
scanf("%d",&T);
while (T--) {
scanf("%lld%lld%lld%lld",&a,&b,&x,&y);
if (a==&&b==) {puts(x==&&y==?"Y":"N"); continue;}
if (a==||b==) gcd=(a==?b:a);
else gcd=__gcd(a,b);
gcd*=;
if (check(x,y,gcd)||check(x-a,y-b,gcd)||check(x-b,y-a,gcd)||check(x-a-b,y-a-b,gcd)) puts("Y");
else puts("N");
}
return ;
}