zoukankan      html  css  js  c++  java
  • [HAOI 2011]向量

    Description

    题库链接

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

    多组数据,数据组数 (t)(1leq tleq 50000)

    Solution

    容易发现这题就只有以下几种操作:

    1. (xpm pcdot 2apm qcdot 2b) ,其中 (p,qinmathbb{Z})
    2. (ypm pcdot 2apm qcdot 2b) ,其中 (p,qinmathbb{Z})
    3. ((x,y)+pcdot(a,b)+qcdot(b,a)) ,其中 (p,qin{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('
    '))
    #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;
    }
  • 相关阅读:
    HDU-1240 Asteroids! (BFS)这里是一个三维空间,用一个6*3二维数组储存6个不同方向
    HDU-1026 Ignatius and the Princess I(BFS) 带路径的广搜
    HDU-1700 Points on Cycle
    HDU-4515 小Q系列故事——世界上最遥远的距离
    Star
    HDOJ5441(图论中的并查集)
    HDOJ5438(图的各个连通分量遍历)
    HDOJ5044(最近公共祖先)
    C++输入输出知识
    JAVAmap容器基本使用
  • 原文地址:https://www.cnblogs.com/NaVi-Awson/p/8428465.html
Copyright © 2011-2022 走看看