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 ...
随机推荐
- 架构 规则引擎 quartz
通向架构师的道路(第五天)之tomcat集群-群猫乱舞-云栖社区-阿里云https://yq.aliyun.com/articles/259343 商业规则引擎和开源规则引擎的测试对比 - qq_39 ...
- OpenCV__type()返回的数字
OpenCV中的类型以宏定义的形式给出 type_c.h中片段 #define CV_CN_MAX 512 #define CV_CN_SHIFT 3 #define CV_DEPTH_MAX (1 ...
- Codeforces 1154G Minimum Possible LCM
题目链接:http://codeforces.com/problemset/problem/1154/G 题目大意: 给定n个数,在这些数中选2个数,使这两个数的最小公倍数最小,输出这两个数的下标(如 ...
- mycat - 水平分表
相对于垂直拆分的区别是:垂直拆分是把不同的表拆到不同的数据库中,而水平拆分是把同一个表拆到不同的数据库中.水平拆分不是将表的数据做分类,而是按照某个字段的某种规则来分散到多个库之中,每个表中包含一部分 ...
- React Native & Google & Proxy
React Native & Google & Proxy https://snack.expo.io/ https://expo.io/snacks/@xgqfrms https:/ ...
- 莫烦theano学习自修第六天【回归】
1. 代码实现 from __future__ import print_function import theano import theano.tensor as T import numpy a ...
- js正則表達式
正則表達式實例化的兩種方式: 字符型 var a=// 對象型var a=new RegExp(,) 修飾符: i:忽略大小寫 g:全局搜索 m:多行搜索 元字符: \轉義字符 \w:字符,數字,下劃 ...
- OPENQUERY (Transact-SQL)
Syntax Copy OPENQUERY ( linked_server ,'query' ) Arguments linked_serverIs an identifier representin ...
- hdu-4300(kmp或者拓展kmp)
题意:乱七八糟说了一大堆,就是先给你一个长度26的字符串,对应了abcd....xyz,这是一个密码表.然后给你一个字符串,这个字符串是不完整的(完整的应该是前半部分是加密的,后半部分是解密了的),然 ...
- Nginx 阻塞与非阻塞
L:32