HDU 5114 扩展欧几里得
题目大意:给你两个球的坐标 他们都往(1, 1)这个方向以相同的速度走,问你他们在哪个位置碰撞。
思路:这种题目需要把x方向和y方向分开来算周期,两个不同周期需要用扩展欧几里得来求第一次相遇。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int>
#define y1 skldjfskldjg
#define y2 skldfjsklejg using namespace std; const int N = 1e6 + ;
const int M = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 +; LL n, m, x1, x2, y1, y2; LL exgcd(LL a, LL b, LL &x, LL &y) {
if(!b) {
x = ; y = ;
return a;
} else {
LL gcd, t; gcd = exgcd(b, a % b, x, y);
t = x; x = y; y = t - (a / b) * y;
return gcd;
}
} int main() { int T; scanf("%d", &T);
for(int cas = ; cas <= T; cas++) {
LL t = -;
scanf("%lld%lld%lld%lld%lld%lld", &n, &m, &x1, &y1, &x2, &y2);
n <<= ; m <<= ; x1 <<= ; y1 <<= ; x2 <<= ; y2 <<= ;
printf("Case #%d:\n", cas);
LL ta = n - (x1 + x2) / ;
LL tb = m - (y1 + y2) / ; if(x1 == x2 && y1 == y2) t = ;
else if(x1 == x2) t = tb;
else if(y1 == y2) t = ta;
else {
LL x, y, gcd;
gcd = exgcd(n, m, x, y);
if((tb - ta) % gcd == ) { x = (tb - ta) / gcd * x;
x = (x % (m / gcd) + m / gcd) % (m / gcd);
t = ta + n * x; }
} if(t == -) {
puts("Collision will not happen.");
} else { x1 = (x1 + t) % ( * n);
y1 = (y1 + t) % ( * m);
if(x1 > n) x1 = * n - x1;
if(y1 > m) y1 = * m - y1;
printf("%.1f %.1f\n", x1 /2.0, y1 /2.0);
}
}
return ;
} /*
*/
HDU 5114 扩展欧几里得的更多相关文章
- hdu 2669(扩展欧几里得)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 4180 扩展欧几里得
RealPhobia Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 2669 扩展欧几里得(裸)
#include<stdio.h> #include<iostream> #define ll __int64 ll gcd(ll a,ll b,ll &x,ll &a ...
- HDU RSA 扩展欧几里得
Problem Description RSA is one of the most powerful methods to encrypt data. The RSA algorithm is de ...
- 扩展欧几里得 hdu 1576
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 不知道扩展欧几里得的同学可以参考:https://blog.csdn.net/zhjchengf ...
- hdu 5512 Pagodas 扩展欧几里得推导+GCD
题目链接 题意:开始有a,b两点,之后可以按照a-b,a+b的方法生成[1,n]中没有的点,Yuwgna 为先手, Iaka后手.最后不能再生成点的一方输: (1 <= n <= 2000 ...
- hdu 1573 A/B (扩展欧几里得)
Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973)= 1). Input 数据的第一行 ...
- hdu 1576 A/B 【扩展欧几里得】【逆元】
<题目链接> <转载于 >>> > A/B Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)( ...
- [ACM] hdu 3923 Invoker (Poyla计数,高速幂运算,扩展欧几里得或费马小定理)
Invoker Problem Description On of Vance's favourite hero is Invoker, Kael. As many people knows Kael ...
随机推荐
- POJ2349:Arctic Network(二分+最小生成树)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28311 Accepted: 8570 题 ...
- ZooKeeper翻译(一)
欢迎来到Apache ZooKeeper的世界 Apache Zookeeper是一个为了开发和维护一个开源的服务的一个尝试,这个服务使高可用的分布式协作成为可能. ZooKeeper是什么? Zoo ...
- intellij idea 中添加maven远程仓库
在intellij idea 中配置好maven后 是这样的 如果加载失败,则需要自定义远程仓库,这里以阿里maven仓库为例, 在项目的pom文件中添加以下配置 <repositories&g ...
- bzoj 2956: 模积和 ——数论
Description 求∑∑((n mod i)*(m mod j))其中1<=i<=n,1<=j<=m,i≠j. Input 第一行两个数n,m. Output 一个整数表 ...
- Html5学习3(拖放、Video(视频)、Input类型(color、datetime、email、month 、number 、range 、search、Tel、time、url、week ))
1.Html拖放 <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> < ...
- NightMare2(SCU4527+dijkstra+二分)
题目链接:http://acm.scu.edu.cn/soj/problem.action?id=4527 题目: 题意:最短路的每条边除了边权之外还会有一个限制(财富,身上带的财富大于这个值则不能通 ...
- HDU 1002 A + B Problem II (大数加法)
题目链接 Problem Description I have a very simple problem for you. Given two integers A and B, your job ...
- recycleView实现item点击更改该item颜色,其它item颜色变回
项目中需要横向滚动效果,按照以前的思路,我会写一个ScrollView,里边加一个LinearLayout,在代码中动态加入控件,然后动态删除或者改变颜色,现在android有了新控件Recycler ...
- windows下常用快捷键(转)
原文转自 https://blog.csdn.net/LJFPHP/article/details/78818696 win+E 打开文件管器 win+D ...
- gnu app url[web][5星]
http://www.gnu.org/software/software.zh-cn.html http://linux.chinaunix.net/news/2010/12/07/1175310.s ...