Codeforces Round 23
来源:互联网 发布:mac 终端连接数据库 编辑:程序博客网 时间:2024/06/06 21:31
Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values x and y written on it. These values define four moves which can be performed using the potion:
Map shows that the position of Captain Bill the Hummingbird is (x1, y1) and the position of the treasure is (x2, y2).
You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes).
The potion can be used infinite amount of times.
The first line contains four integer numbers x1, y1, x2, y2 ( - 105 ≤ x1, y1, x2, y2 ≤ 105) — positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers x, y (1 ≤ x, y ≤ 105) — values on the potion bottle.
Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes).
0 0 0 62 3
YES
1 1 3 61 5
NO
In the first example there exists such sequence of moves:
- — the first type of move
- — the third type of move
- 、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、2
SOLUTION:Firstly, let's approach this problem as if the steps were and . Then the answer is "YES" if |x1 - x2| mod x = 0 and |y1 - y2| mod y = 0.
It's easy to see that if the answer to this problem is "NO" then the answer to the original one is also "NO".
Let's return to the original problem and take a look at some sequence of steps. It ends in some point (xe, ye). Define cntx as and cnty as . The parity of cntx is the same as the parity of cnty. It is like this because every type of move changes parity of both cntx and cnty.
So the answer is "YES" if |x1 - x2| mod x = 0, |y1 - y2| mod y = 0 and mod mod 2.
Overall complexity: O(1).
#include<bits/stdc++.h>using namespace std;int main(){int a,b,p,q,x,y;cin>>a>>b>>p>>q>>x>>y;if((p-a)%x==0 && (q-b)%y==0 && ((p-a)/x+(q-b)/y)%2==0) cout<<"YES"<<endl;else cout<<"NO";}
- Codeforces Beta Round #23
- Codeforces Beta Round #23
- Codeforces Round 23
- Educational Codeforces Round 23总结
- [CF] Educational Codeforces Round 23
- Educational Codeforces Round 23 A
- Educational Codeforces Round 23 B
- Educational Codeforces Round 23 题解
- 【codeforces】Codeforces Round #363
- B. Party – Codeforces Beta Round #23
- Educational Codeforces Round 23 A. Treasure Hunt
- Educational Codeforces Round 23 A-F
- Educational Codeforces Round 23#A. Treasure Hunt
- Codeforces Round #270 Codeforces Round #270
- 【Codeforces】Codeforces Round #271 div2
- 【CODEFORCES】 Educational Codeforces Round 1
- Codeforces Educational Codeforces Round 5
- Codeforces Round #403 div2 (CodeForces
- PyCharm使用技巧:Find Action(查找并跳转到设置界面)
- [TetraMAX]set_delay -launch_cycle last_shift 的含义
- HDU
- 法规数字分类
- <QT>常见错误总结
- Codeforces Round 23
- sofia-sip下载地址
- 记忆化搜索 哈工大1865
- 进程程序替换
- 非常好的理解遗传算法的例子
- lowest node's LCA
- 一些有用的网站:
- 免费文献下载
- (总结)Nginx与Apache、Tomcat、Resin动静分离核心配置