BZOJ2299 [HAOI2011]向量 【裴蜀定理】

题目链接

BZOJ2299

题解

题意就是给我们四个方向的向量\((a,b),(b,a),(-a,b),(b,-a)\),求能否凑出\((x,y)\)
显然我们就可以得到一对四元方程组,用裴蜀定理判断一下方程有没有解即可

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 100005,maxm = 100005,INF = 1000000000;
inline int read(){
    int out = 0,flag = 1; char c = getchar();
    while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
    while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
    return out * flag;
}
LL a,b,x,y,tmp;
LL gcd(LL a,LL b){return b ? gcd(b,a % b) : a;}
int main(){
    int T = read();
    while (T--){
        a = read(); b = read(); x = read(); y = read();
        if (a < b) swap(a,b);
        tmp = gcd(gcd(2 * a * b,a * a + b * b),a * a - b * b);
        if ((b * x - a * y) % tmp || (b * x + a * y) % tmp || (a * x - b * y) % tmp || (a * x + b * y) % tmp)
            puts("N");
        else puts("Y");
    }
    return 0;
}

转载于:https://www.cnblogs.com/Mychael/p/9055339.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值