题目描述
给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), (-b,a), (-b,-a)这些向量,问你能不能拼出另一个向量(x,y)。
说明:这里的拼就是使得你选出的向量之和为(x,y)
输入输出格式
输入格式:
第一行数组组数t,(t<=50000)
接下来t行每行四个整数a,b,x,y (-2*109<=a,b,x,y<=2*109)
输出格式:
t行每行为Y或者为N,分别表示可以拼出来,不能拼出来
输入输出样例
输入样例#1: 复制
3
2 1 3 3
1 1 0 1
1 0 -2 3
输出样例#1: 复制
Y
N
Y
说明
样例解释:
第一组:(2,1)+(1,2)=(3,3)
第三组:(-1,0)+(-1,0)+(0,1)+(0,1)+(0,1)=(-2,3)
其实只是
(a,b),(b,a),(a,-b),(b,-a)这四种的组合;
----->
k(a,b)+p(b,a)+q(a,-b)+w(b,-a)==(x,y);
化简---->
(k+q)a+(p+w)b=x; (p-w)a+(k-q)b=y;
考虑:
ax+by=c的解集;
有解当且仅当 gcd( a,b ) | c;
又k,q,p,w都为整数;
但:
满足 k+q∈z, k-q∈z ,不一定会有 k,q∈z;
不妨设 k+q = f,k-q = g;
求解----->k=( f+g )/2; q= ( f-g )/2;
所以f,g全为奇数or 偶数;
所以考虑四种情况:
① k+q,k-q,p+w,p-w为偶数;
②k+q,k-q为奇数,p+w,p-w为偶数;
③k+q,k-q为偶数,p+w,p-w为奇数;
④k+q,k-q,p+w,p-w为奇数;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 600005
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 20100403
#define sq(x) (x)*(x)
#define eps 1e-15
const int N = 2500005;
inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }
ll t, a, b, c, d;
ll k;
bool check(ll x, ll y) {
if (x%k == 0 && y%k == 0)return true;
return false;
}
int main()
{
//ios::sync_with_stdio(false);
rdllt(t);
while (t--) {
rdllt(a); rdllt(b); rdllt(c); rdllt(d);
k = gcd(a, b) * 2;
if (check(c, d) || check(c + a, d+b) || check(c+b, d + a) || check(c + a+b, d + b+a))
cout << "Y" << endl;
else cout << "N" << endl;
}
return 0;
}