BZOJ 2299 向量(裴蜀定理)
题意:给你一对数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-8 # define MOD 30031 # define INF 1000000000 # 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<<1,l,mid # define rch p<<1|1,mid+1,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=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } const int N=1000005; //Code begin... bool check(LL x, LL y, LL gcd){return x%gcd==0&&y%gcd==0;} 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==0&&b==0) {puts(x==0&&y==0?"Y":"N"); continue;} if (a==0||b==0) gcd=(a==0?b:a); else gcd=__gcd(a,b); gcd*=2; 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 0; }