zoukankan      html  css  js  c++  java
  • codeforces 101C C. Vectors(数学)

    题目链接:

    C. Vectors

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    At a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector А:

    • Turn the vector by 90 degrees clockwise.
    • Add to the vector a certain vector C.

    Operations could be performed in any order any number of times.

    Can Gerald cope with the task?

    Input

    The first line contains integers x1 и y1 — the coordinates of the vector A ( - 108 ≤ x1, y1 ≤ 108). The second and the third line contain in the similar manner vectors B and C (their coordinates are integers; their absolute value does not exceed 108).

    Output

    Print "YES" (without the quotes) if it is possible to get vector B using the given operations. Otherwise print "NO" (without the quotes).

    Examples
    input
    0 0
    1 1
    0 1
    output
    YES
    input
    0 0
    1 1
    1 1
    output
    YES
    input
    0 0
    1 1
    2 2
    output
    NO

    题意:

    两个操作,1把A向量旋转90度,2把C向量加到A向量上,现在两个操作可以执行任意多次,顺序也是任意的,问能否得到B向量;

    思路:

    假设D为C旋转90度的向量,E为A旋转后的向量;
    可以发现最后得到的都是a*C+b*D=B-E;
    这就变成了一个判断一个二元一次方程组是否有整数解的问题;
    那么就判断好了;

    AC代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <bits/stdc++.h>
    #include <stack>
    #include <map>
      
    using namespace std;
      
    #define For(i,j,n) for(int i=j;i<=n;i++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
      
    typedef  long long LL;
      
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
      
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const LL inf=1e18;
    const int N=(1<<20)+10;
    const int maxn=1e6+10;
    const double eps=1e-12;
     
    LL ax,ay,bx,by,cx,cy;
    int solve(LL x,LL y)
    {
        x=bx-x;y=by-y;
        if(cx==0&&cy==0)
        {
            if(x==0&&y==0)return 1;
            return 0;
        }
        else if(cx==0)
        {
            LL g=x/cy,h=y/cy;
            if(g*cy==x&&h*cy==y)return 1;
            return 0;
        }
        else if(cy==0)
        {
            LL g=x/cx,h=y/cx;
            if(g*cx==x&&h*cx==y)return 1;
            return 0;
        }
        else 
        {
            LL tx=x*cy,ty=y*cx;
            LL b=(tx-ty)/(cy*cy+cx*cx);
            if(b*(cx*cx+cy*cy)!=(tx-ty))return 0;
            else 
            {
                LL a=(x-b*cy)/cx;
                if(a*cx+b*cy==x)return 1;
                return 0;
            }
        }
    }
    int main()
    {
        read(ax);read(ay);
        read(bx);read(by);
        read(cx);read(cy);
        int f=0;
        if(solve(ax,ay))f=1;
        if(solve(-ax,-ay))f=1;
        if(solve(ay,-ax))f=1;
        if(solve(-ay,ax))f=1;
        if(f)cout<<"YES
    ";
        else cout<<"NO
    ";
        return 0;
    }
    

      

  • 相关阅读:
    总结
    PHP的重载-使用魔术方法实现
    用PHP实现一些常见的排序算法
    MySQL分组聚合group_concat + substr_index
    各种链接地址
    在Linux服务器上使用rz命令上传文件时时老报:Segmentation Fault,上传失败
    新安装的windows 10无法更新报0x80240fff错误的解决方案
    通过SSH key获取GitHub上项目,导入到IDEA中
    解压.zip,.tar.gz文件到指定目录,重命名文件
    byte字节数组的压缩
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5900666.html
Copyright © 2011-2022 走看看