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('\n');
}
  
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\n";
    else cout<<"NO\n";
    return 0;
}

  

转载于:https://www.cnblogs.com/zhangchengc919/p/5900666.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值