• BZOJ2299: [HAOI2011]向量


    2299: [HAOI2011]向量

    Description

    给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), (-b,a), (-b,-a)这些向量,问你能不能拼出另一个向量(x,y)。

    说明:这里的拼就是使得你选出的向量之和为(x,y)

    Input

    第一行数组组数t,(t<=50000)

    接下来t行每行四个整数a,b,x,y  (-2*109<=a,b,x,y<=2*109)

    Output

    t行每行为Y或者为N,分别表示可以拼出来,不能拼出来

    Sample Input

    3

    2 1 3 3

    1 1 0 1

    1 0 -2 3

    Sample Output

    Y

    N

    Y




    HINT

     



    样例解释:



    第一组:(2,1)+(1,2)=(3,3)



    第三组:(-1,0)+(-1,0)+(0,1)+(0,1)+(0,1)=(-2,3)

    Source

    这题,我一开始的思路是设元,利用奇偶性判。不过显然是不行的,(反例随手找)
    身为蒟蒻的无奈,看了看大神的题解,%%%。
    我们可以从给出的8个向量进行归总和配对。
    就能得到几种基本操作:
    x或y加减两倍a或b,x加a,y加b或y加a,a加b。
    因为两次后面的操作可以用前面的操作代替,所以后面的操作只可能做一次。
    枚举一下就行了,QAQ。
     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<cstdlib>
     7 #include<vector>
     8 using namespace std;
     9 typedef long long ll;
    10 typedef long double ld;
    11 typedef pair<int,int> pr;
    12 const double pi=acos(-1);
    13 #define rep(i,a,n) for(int i=a;i<=n;i++)
    14 #define per(i,n,a) for(int i=n;i>=a;i--)
    15 #define Rep(i,u) for(int i=head[u];i;i=Next[i])
    16 #define clr(a) memset(a,0,sizeof(a))
    17 #define pb push_back
    18 #define mp make_pair
    19 #define fi first
    20 #define sc second
    21 #define pq priority_queue
    22 #define pqb priority_queue <int, vector<int>, less<int> >
    23 #define pqs priority_queue <int, vector<int>, greater<int> >
    24 #define vec vector
    25 ld eps=1e-9;
    26 ll pp=1000000007;
    27 ll mo(ll a,ll pp){if(a>=0 && a<pp)return a;a%=pp;if(a<0)a+=pp;return a;}
    28 ll powmod(ll a,ll b,ll pp){ll ans=1;for(;b;b>>=1,a=mo(a*a,pp))if(b&1)ans=mo(ans*a,pp);return ans;}
    29 void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
    30 //void add(int x,int y,int z){ v[++e]=y; next[e]=head[x]; head[x]=e; cost[e]=z; }
    31 int dx[5]={0,-1,1,0,0},dy[5]={0,0,0,-1,1};
    32 ll read(){ ll ans=0; char last=' ',ch=getchar();
    33 while(ch<'0' || ch>'9')last=ch,ch=getchar();
    34 while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
    35 if(last=='-')ans=-ans; return ans;
    36 }
    37 ll a,b,x,y,d;
    38 int check(ll x,ll y){
    39     if (x%d==0 && y%d==0) return 1;
    40     return 0;
    41 }
    42 int main()
    43 {
    44     int T=read();
    45     while (T--){
    46         a=read(),b=read(),x=read(),y=read(); d=__gcd(2*a,2*b);
    47         if (check(x,y)||check(x+a,y+b)||check(x+b,y+a)||check(x+a+b,y+a+b)) puts("Y");
    48         else puts("N");
    49     }
    50     return 0;
    51  } 
    View Code
     
     
  • 相关阅读:
    Html学习_简易个人网页制作
    Html学习_style属性应用
    xode9.0的xcodebuild -exportArchive -archivePath 导出ipa包报错Error Domain=IDEProvisioningErrorDomain Code=3
    xcode8,Application Loader上传ipa包iTunes connect不显示构建版本问题
    git统计代码总行数
    Gerri review 代码管理规范
    ! [remote rejected] HEAD -> refs/for/ToonV3.0 (missing Change-Id in commit message footer)
    git分支管理和冲突
    Gerrit出现 Submitted, Merge Pending 和 Merge Conflict
    Git命令大全
  • 原文地址:https://www.cnblogs.com/SXia/p/6791604.html
Copyright © 2020-2023  润新知