Billiard CFR484 div2 (数论)
就是一个点从开始的点在一个矩形内往某个方向一直运动,如果碰到了矩形的边,那么就反弹,我们可以把这个矩形拓展开,那么就是问题变成了我有没有一个点,这个点的坐标(Tx, Ty)满足n|Tx,m|Ty
那么假设有的话,那么这个直线的方程化简以后就是就是n*xx+m*yy = y-x,然后问题就变成了这个方程有没有解,如果我无解,那么就是-1,如果有解,那么就求出xx和yy的最小值,然后通过xx,yy的奇偶性来判断我进入边界的位置是哪里.
这是对于方向在右上角的,对于其他方向上我们可以转化到右上角,比如如果是左上角,那么就可以让现在的x = n - x, 最后的答案xx进行相应的变化 xx = n - xx,其他方向同理。
#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define first fi
#define second se
#define lowbit(x) (x & (-x)) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = ;
const int maxm = ;
using namespace std; int n, m, tol, T; ll e_gcd(ll a, ll b, ll &x, ll &y) {
if(b == ) {
x = ;
y = ;
return a;
} else {
ll d = e_gcd(b, a%b, x, y);
ll tmp = y;
y = x - a/b*y;
x = tmp;
return d;
}
} int main() {
int x,y,vx,vy;
scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &vx, &vy);
if(vx == && vy == ) {
printf("-1\n");
return ;
}
if(vx == ) {
if(x == n || x == ) {
if(vy == )
printf("%d %d\n", x, m);
else
printf("%d %d\n", x, );
} else {
printf("-1\n");
}
return ;
}
if(vy == ) {
if(y == m || y == ) {
if(vx == )
printf("%d %d\n", n, y);
else
printf("%d %d\n", , y);
} else {
printf("-1\n");
}
return ;
}
bool fx = false;
bool fy = false;
if(vx == -) {
fx = true;
x = n - x;
}
if(vy == -) {
fy = true;
y = m - y;
}
ll a = n;
ll b = m;
ll c = x - y;
ll xx, yy;
ll d = e_gcd(a, b, xx, yy);
if(c % d) {
printf("-1\n");
return ;
}
ll r = b / d;
ll cx = ((c/d) * xx % r + r + r - ) %r + ;
ll cy = (cx * n - c) / m;
ll ansx, ansy;
if(cx & ) {
ansx = n;
} else {
ansx = ;
}
if(cy & ) {
ansy = m;
} else {
ansy = ;
}
if(fx) ansx = (ll)n - ansx;
if(fy) ansy = (ll)m - ansy;
printf("%lld %lld\n", ansx, ansy);
return ;
}
Billiard CFR484 div2 (数论)的更多相关文章
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【数论】【扩展欧几里得】Codeforces Round #484 (Div. 2) E. Billiard
题意:给你一个台球桌面,一个台球的初始位置和初始速度方向(只可能平行坐标轴或者与坐标轴成45度角),问你能否滚进桌子四个角落的洞里,如果能,滚进的是哪个洞. 如果速度方向平行坐标轴,只需分类讨论,看它 ...
- 【cf 483 div2 -C】Finite or not?(数论)
链接:http://codeforces.com/contest/984/problem/C 题意 三个数p, q, b, 求p/q在b进制下小数点后是否是有限位. 思路 题意转化为是否q|p*b^x ...
- 【BZOJ1876】[SDOI2009]SuperGCD(数论,高精度)
[BZOJ1876][SDOI2009]SuperGCD(数论,高精度) 题面 BZOJ 洛谷 题解 那些说数论只会\(gcd\)的人呢?我现在连\(gcd\)都不会,谁来教教我啊? 显然\(gcd\ ...
- CCPC-Wannafly Winter Camp Day3 (Div2, onsite)
Replay Dup4: 没想清楚就动手写? 写了两百行发现没用?想的还是不够仔细啊. 要有莽一莽的精神 X: 感觉今天没啥输出啊, 就推了个公式?抄了个板子, 然后就一直自闭A. 语文差,题目没理解 ...
- CCPC-Winter Camp div2 day5
DIV2 有部分div1的题会写 div1的大佬真的太强了 向他们学习 (好像和zqc大佬说过话了hhh,zqc大佬真的是一个超有意思的人啊,羡慕有妹子队友的zqc大佬) A: 你有一棵树,你想把它画 ...
- topcpder SRM 664 div2 A,B,C BearCheats , BearPlays equalPiles , BearSorts (映射)
A题,熊孩子测视力,水题,题意就是判断一下两个数对应位不相同的数字有多少个. #include<bits/stdc++.h> using namespace std; class Bear ...
- Codeforces Round #382 Div. 2【数论】
C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...
- bc#54 div2
用小号做的div2 A:竟然看错了排序顺序...白白WA了两发 注意读入一整行(包括空格):getline(cin,st) [gets也是资瓷的 #include<iostream> us ...
随机推荐
- PAT L3-007 天梯地图
https://pintia.cn/problem-sets/994805046380707840/problems/994805051153825792 本题要求你实现一个天梯赛专属在线地图,队员输 ...
- Errors running builder 'DeploymentBuilder' on project
Errors running builder 'DeploymentBuilder' on project 1.修改java源代码后点击保存,IDE 自动编译并热部署,提示如下错误: Errors o ...
- 深浅copy详解
一. 前言 在python中,对象的赋值和深浅copy,是有差异的.最终得的值也不同,下面我们就通过几个例子,来看下它们之间的区别. 二. 赋值 list2 = ["jack",2 ...
- npm --save-dev 和--save 参数的区别
npm中的--save与--save-dev参数的区别 --save一般规定把产品运行时(或生产环境)需要的npm包存入到package.json的dependencies中: --save-dev则 ...
- 关于 html input标签的几个常用操作
1.清除 input 标签默认样式 input { -moz-appearance: none; outline: 0; text-decoration: none; outline: none; b ...
- Spring Aop实例@Aspect、@Before、@AfterReturning@Around 注解方式配置
用过spring框架进行开发的人,多多少少会使用过它的AOP功能,都知道有@Before.@Around和@After等advice.最近,为了实现项目中的输出日志和权限控制这两个需求,我也使用到了A ...
- IWMS后台上传文章,嵌入音频文件代码
<object width="260" height="69" classid="clsid:6bf52a52-394a-11d3-b153-0 ...
- 如何使用命令从linux服务器下载文件到windows
1.直接使用命令从linux下载文件到windows //登录linux服务器导出mysql数据 mysqldump -hrm-2ze8mpi5i65429l1q.mysql.rds.aliyuncs ...
- 三、安装MyCat-Web
一.下载和解压MyCat-web http://dl.mycat.io/mycat-web-1.0/ wget http://dl.mycat.io/mycat-web-1.0/Mycat-web-1 ...
- js 持续访问保持session对象不消失
$(function(){ publicBusi(); }) //实时刷新登录用户信息 function publicBusi(){ setTimeout(publicBusi,1000*60*10) ...