zoukankan      html  css  js  c++  java
  • BZOJ2299 HAOI2011向量(数论)

      设最后的组成为x=x0a+x1b,y=y0a+y1b。那么容易发现x0和y0奇偶性相同、x1和y1奇偶性相同。于是考虑奇偶两种情况,问题就变为是否存在x和y使ax+by=c,那么其充要条件是gcd(a,b)|c。

    #include<iostream> 
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    int read()
    {
        int x=0,f=1;char c=getchar();
        while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
        while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
        return x*f;
    }
    int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
    bool check(int a,int b,long long x,long long y)
    {
        if (x&1) return 0;
        if (y&1) return 0;
        x>>=1,y>>=1;
        int n=gcd(a,b);
        return x%n==0&&y%n==0; 
    }
    int main()
    {
    #ifndef ONLINE_JUDGE
        freopen("bzoj2299.in","r",stdin);
        freopen("bzoj2299.out","w",stdout);
        const char LL[]="%I64d
    ";
    #else
        const char LL[]="%lld
    ";
    #endif
        int T=read();
        while (T--)
        {
            int a=read(),b=read();long long x=read(),y=read();
            if (check(a,b,x,y)||check(a,b,x-a,y-b)||check(a,b,x-b,y-a)||check(a,b,x-a-b,y-a-b)) printf("Y
    ");
            else printf("N
    ");
        }
        return 0;
    }
  • 相关阅读:
    vim
    Linux 软链接和硬链接
    常用命令
    linux 二级目录结构
    关于bash shell的理解
    虚拟机网络模式
    安装虚拟机
    date 命令
    使用3种协议搭建yum仓库
    ubuntu update时发生错误
  • 原文地址:https://www.cnblogs.com/Gloid/p/9558049.html
Copyright © 2011-2022 走看看