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;
    }
  • 相关阅读:
    6.1 tar:打包备份
    6.3-4 zip、unzip
    6.5 scp:远程文件复制
    S7 Linux用户管理及用户信息查询命令
    7.6 passwd:修改用户密码
    7.2-5 usermod
    DES
    FreeRTOS笔记
    第4章 裸机系统和多任务系统
    第008课_第1个ARM落版程序及引申
  • 原文地址:https://www.cnblogs.com/Gloid/p/9558049.html
Copyright © 2011-2022 走看看