Description
给你一对数 \(a,b\) ,你可以任意使用 \((a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), (-b,a), (-b,-a)\) 这些向量,问你能不能拼出另一个向量 \((x,y)\) 。
多组数据,数据组数 \(t\) , \(1\leq t\leq 50000\)
Solution
容易发现这题就只有以下几种操作:
- 给 \(x\pm p\cdot 2a\pm q\cdot 2b\) ,其中 \(p,q\in\mathbb{Z}\) ;
- 给 \(y\pm p\cdot 2a\pm q\cdot 2b\) ,其中 \(p,q\in\mathbb{Z}\) ;
- 给 \((x,y)+p\cdot(a,b)+q\cdot(b,a)\) ,其中 \(p,q\in\{0,1\}\)
用扩展欧几里得的那套理论乱搞就好了。
我还是太菜了啊,一开始写了个大讨论,发现不好写,看了学弟的博客才会...被学弟爆踩。
Code
//It is made by Awson on 2018.2.7
#include <bits/stdc++.h>
#define LL long long
#define dob complex<double>
#define Abs(a) ((a) < 0 ? (-(a)) : (a))
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Swap(a, b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))
#define writeln(x) (write(x), putchar('\n'))
#define lowbit(x) ((x)&(-(x)))
using namespace std;
void read(LL &x) {
char ch; bool flag = 0;
for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
for (x = 0; isdigit(ch); x = (x<<1)+(x<<3)+ch-48, ch = getchar());
x *= 1-2*flag;
}
void print(int x) {if (x > 9) print(x/10); putchar(x%10+48); }
void write(int x) {if (x < 0) putchar('-'); print(Abs(x)); }
LL a, b, x, y, t, g;
LL gcd(LL a, LL b) {return b ? gcd(b, a%b) : a; }
bool check(LL a, LL b) {return a%g == 0 && b%g == 0; }
void work() {
read(t);
while (t--) {
read(a), read(b), read(x), read(y);
g = gcd(a*2, b*2);
if (check(x, y) || check(x+a, y+b) || check(x+b, y+a) || check(x+a+b, y+a+b)) puts("Y");
else puts("N");
}
}
int main() {
work(); return 0;
}