[HAOI2011]向量

Description
给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), (-b,a), (-b,-a)这些向量,问你能不能拼出另一个向量(x,y)。
说明:这里的拼就是使得你选出的向量之和为(x,y)

Input
第一行数组组数t,(t<=50000)
接下来t行每行四个整数a,b,x,y (-2109<=a,b,x,y<=2109)

Output
t行每行为Y或者为N,分别表示可以拼出来,不能拼出来

Sample Input
3
2 1 3 3
1 1 0 1
1 0 -2 3

Sample Output
Y
N
Y

HINT
样例解释:
第一组:(2,1)+(1,2)=(3,3)
第三组:(-1,0)+(-1,0)+(0,1)+(0,1)+(0,1)=(-2,3)


其实就是个数论题。。。

其实我们观察可以发现,\((x,y)\rightarrow (x,y\pm 2b)\)\((x,y)\rightarrow (x\pm 2a,y)\),而且本题正负是没有意义的

因此我们只需要判断第一步出发的四种特殊情况能不能到达即可,特殊情况分为\((x,y),(x+a,y+b),(x+b,y+a),(x+a+b,y+a+b)\)四种

/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
	static char buf[1000000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
	int x=0,f=1; char ch=gc();
	for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')	f=-1;
	for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}
inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}
inline void print(int x){
	if (x<0)	putchar('-'),x=-x;
	if (x>9)	print(x/10);
	putchar(x%10+'0');
}
ll d;
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
bool ck(ll x,ll y){return x%d==0&&y%d==0;}
int main(){
	ll a,b,x,y;
	for (int T=read();T;T--){
		scanf("%lld%lld%lld%lld",&a,&b,&x,&y),d=gcd(a,b)<<1;
		printf(ck(x,y)||ck(x+a,y+b)||ck(x+b,y+a)||ck(x+a+b,y+a+b)?"Y\n":"N\n");
	}
	return 0;
}
posted @ 2018-11-22 17:17  Wolfycz  阅读(153)  评论(0编辑  收藏  举报