第七届河南省赛10402: C.机器人(扩展欧几里德)
10402: C.机器人
Time Limit: 2 Sec Memory Limit: 128 MB Submit: 53 Solved: 19 [Submit][Status][Web Board]
Description
Dr. Kong 设计的机器人卡尔非常活泼,既能原地蹦,又能跳远。由于受软硬件设计所限,机器人卡尔只能定点跳远。若机器人站在(X,Y)位置,它可以原地蹦,但只可以在(X,Y),(X,-Y),(-X,Y),(-X,-Y),(Y,X),(Y,-X),(-Y,X),(-Y,-X)八个点跳来跳去。
现在,Dr. Kong想在机器人卡尔身上设计一个计数器,记录它蹦蹦跳跳的数字变化(S,T),即,路过的位置坐标值之和。
你能帮助Dr. Kong判断机器人能否蹦蹦跳跳,拼出数字(S,T)吗?
假设机器人卡尔初始站在(0,0)位置上。
Input
第一行: K 表示有多少组测试数据。
接下来有K行,每行:X Y S T
1≤K≤10000 -2*109 <= X , Y, S, T <= 2*109
数据之间有一个空格。
Output
对于每组测试数据,输出一行:Y或者为N,分别表示可以拼出来,不能拼出来
Sample Input
3
2 1 3 3
1 1 0 1
1 0 -2 3
Sample Output
Y
N
Y
HINT
Source
题解:机器人在一个区域内随便跳,记录坐标变化值;每给两组数据都有
(a1+a2)x + (a3+a4)y = s; ---> Ax + By = s;
(a1-a2)y + (a3-a4)x = t; ---> Cx + Dy = t;
由此可见A+C,和B+D都是偶数;所以给定Ax + By = s;Cx + Dy = t;
若有转换成立必定有A+D,和B+C都是偶数;所以转换为求两个方程式的解,解出x,y;也就是上面的A,B,C,D;然后判断有没有解;
代码:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
#define SI(x) scanf("%d",&x)
#define mem(x,y) memset(x,y,sizeof(x))
#define PI(x) printf("%d",x)
#define P_ printf(" ")
const int INF=0x3f3f3f3f;
typedef long long LL;
LL ex_gcd(LL a,LL b,LL &x,LL &y){
if(!b){
x=1;
y=0;
return a;
}
LL d=ex_gcd(b,a%b,x,y);
LL temp=x;
x=y;
y=temp-a/b*y;
return d;
}
int main(){
int K;
LL X,Y,S,T;
SI(K);
while(K--){
scanf("%lld%lld%lld%lld",&X,&Y,&S,&T);
LL gcd,a,b,c,d;
gcd=ex_gcd(X,Y,a,b);
if(S%gcd!=0||T%gcd!=0){
puts("N");continue;
}
c=a*T/gcd;d=b*T/gcd;
a*=S/gcd;b*=S/gcd;
LL x1,y1,x2,y2;
int flot=0;
for(int t1=-2;t1<=2;t1++){
x1=a+Y/gcd*t1;y1=b-X/gcd*t1;
for(int t2=-2;t2<=2;t2++){
x2=c+Y/gcd*t2;y2=d-X/gcd*t2;
if((x1+y2)%2==0&&(x2+y1)%2==0)flot=1;
}
}
if(flot)puts("Y");
else puts("N");
}
return 0;
}
第七届河南省赛10402: C.机器人(扩展欧几里德)的更多相关文章
- 第七届河南省赛10403: D.山区修路(dp)
10403: D.山区修路 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 69 Solved: 23 [Submit][Status][Web Bo ...
- 第七届河南省赛G.Code the Tree(拓扑排序+模拟)
G.Code the Tree Time Limit: 2 Sec Memory Limit: 128 MB Submit: 35 Solved: 18 [Submit][Status][Web ...
- 第七届河南省赛B.海岛争霸(并差集)
B.海岛争霸 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 130 Solved: 48 [Submit][Status][Web Board] D ...
- 第七届河南省赛A.物资调度(dfs)
10401: A.物资调度 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 95 Solved: 54 [Submit][Status][Web Bo ...
- 第七届河南省赛H.Rectangles(lis)
10396: H.Rectangles Time Limit: 2 Sec Memory Limit: 128 MB Submit: 229 Solved: 33 [Submit][Status] ...
- 第七届河南省赛F.Turing equation(模拟)
10399: F.Turing equation Time Limit: 1 Sec Memory Limit: 128 MB Submit: 151 Solved: 84 [Submit][St ...
- 山东省第七届省赛 D题:Swiss-system tournament(归并排序)
Description A Swiss-system tournament is a tournament which uses a non-elimination format. The first ...
- poj 2567 Code the Tree 河南第七届省赛
Code the Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2350 Accepted: 906 Desc ...
- 第六届河南省赛 River Crossing 简单DP
1488: River Crossing Time Limit: 1 Sec Memory Limit: 128 MB Submit: 83 Solved: 42 SubmitStatusWeb ...
随机推荐
- MySql: Column 'XXXX' in field list is ambiguous 错误
[Err] 1052 - Column 'XXXX' in field list is ambiguous 例如: SELECT id, a.name, price, `describe`, scho ...
- VMware ESXI4.1 常用命令
一. VMware ESX Command 1. # vmware –v (查看esx版本) 2. # esxcfg-info -a(查看显示ESX硬件,内核,存储,网络等信息) # esxcfg- ...
- android 设置头像以及裁剪功能
在android的开发过程中,经常遇到设置用户头像以及裁剪图像大小的功能.昨天我遇到了设置用户头像的功能,开始不知道怎么搞,在技术群里问也没人回 答,就研究了微信用户设置头像的功能,了解到用户设置图像 ...
- 快速傅里叶变换FFT
多项式乘法 #include <cstdio> #include <cmath> #include <algorithm> #include <cstdlib ...
- &&与||的用法总结
a() && b() :如果执行a()后返回true,则执行b()并返回b的值:如果执行a()后返回false,则整个表达式返回a()的值,b()不执行: a() || b() :如果 ...
- python setattr(),getattr()函数
setattr(object,name,value): 作用:设置object的名称为name(type:string)的属性的属性值为value,属性name可以是已存在属性也可以是新属性. get ...
- html学习笔记一
学习了一天,总结巩固下自己收获. html是超文本标记语言,而不是编程语言. 1:html结构 包含html标签,head标签,title标签,body标签. <html> <hea ...
- windows 7 memcached报failed to install service or service already installed的解决方案
今天心血来潮捣鼓一下memcache,由于系统是windows 7,我参考了 Windows下安装Memcache 使用memcached for Win32. 在运行memcached.exe -d ...
- ubuntu系统安装FTP
Ubuntu安装vsftp软件 1.更新软件源 首先须要更新系统的软件源,便捷工具下载地址:http://help.aliyun.com/manual?spm=0.0.0.0.zJ3dBU&h ...
- Ubuntu下用glade和GTK+开发C语言界面程序(三)——学习make的使用方法
makefile的规则 makefile的规则例如以下: target ... : prerequisites ... command ... ... target能够是一个object file(目 ...