HDU 5114 Collision
Collision
Time Limit: 15000/15000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 864 Accepted Submission(s): 206
Problem Description
Matt is playing a naive computer game with his deeply loved pure girl.
The playground is a rectangle with walls around. Two balls are put in different positions inside the rectangle. The balls are so tiny that their volume can be ignored. Initially, two balls will move with velocity (1, 1). When a ball collides with any side of the rectangle, it will rebound without loss of energy. The rebound follows the law of refiection (i.e. the angle at which the ball is incident on the wall equals the angle at which it is reflected).
After they choose the initial position, Matt wants you to tell him where will the two balls collide for the first time.
Input
The first line contains only one integer T which indicates the number of test cases.
For each test case, the first line contains two integers x and y. The four vertices of the rectangle are (0, 0), (x, 0), (0, y) and (x, y). (1 ≤ x, y ≤ 105)
The next line contains four integers x1, y1, x2, y2. The initial position of the two balls is (x1, y1) and (x2, y2). (0 ≤ x1, x2 ≤ x; 0 ≤ y1, y2 ≤ y)
Output
For each test case, output “Case #x:” in the first line, where x is the case number (starting from 1).
In the second line, output “Collision will not happen.” (without quotes) if the collision will never happen. Otherwise, output two real numbers xc and yc, rounded to one decimal place, which indicate the position where the two balls will first collide.
Sample Input
3
10 10
1 1 9 9
10 10
0 5 5 10
10 10
1 0 1 10
Sample Output
Case #1:
6.0 6.0
Case #2:
Collision will not happen.
Case #3:
6.0 5.0
Hint
In first example, two balls move from (1, 1) and (9, 9) both with velocity (1, 1), the ball starts from (9, 9) will rebound at point (10, 10) then move with velocity (−1, −1). The two balls will meet each other at (6, 6).
Source
2014ACM/ICPC亚洲区北京站-重现赛(感谢北师和上交)
解析:扩展欧几里得。参考[http://www.cnblogs.com/TenderRun/p/5943453.html](http://www.cnblogs.com/TenderRun/p/5943453.html)。
```
#include
typedef long long ll;
ll ta,tb,x,y, time;
int T,n,m,x1,y1,x2,y2;
ll extgcd(ll a, ll b, ll &x, ll &y)
{
if(b == 0){
x = 1;
y = 0;
return a;
}
ll q = extgcd(b, a%b, y, x);
y -= a/b*x;
return q;
}
int main()
{
int cn = 0;
scanf("%d",&T);
while(T--){
scanf("%d%d%d%d%d%d", &n, &m, &x1, &y1, &x2, &y2);
n = 2 ;m = 2; x1 = 2; y1 = 2; x2 = 2; y2 = 2;
ta = n-(x1+x2)/2; tb = m-(y1+y2)/2;
printf("Case #%d:\n",++cn);
time = -1;
if(x1 == x2 && y1 == y2) time = 0;
else if(y1y2) time = ta;
else if(x1x2) time = tb;
else{
ll d = extgcd(n,m,x,y);
if((tb-ta)%d==0){
x = (tb-ta)/dx;
x = (x%(m/d)+m/d)%(m/d);
time = ta+nx;
}
}
if(time == -1)
puts("Collision will not happen.");
else{
x1 = (x1+time)%(2n); y1 = (y1+ time)%(2m);
if(x1>n) x1 = 2n-x1;
if(y1>m) y1 = 2m-y1;
printf("%.1f %.1f\n", x1/2.0, y1/2.0);
}
}
return 0;
}
HDU 5114 Collision的更多相关文章
- 数学(扩展欧几里得算法):HDU 5114 Collision
Matt is playing a naive computer game with his deeply loved pure girl. The playground is a rectangle ...
- HDU 4793 Collision(2013长沙区域赛现场赛C题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4793 解题报告:在一个平面上有一个圆形medal,半径为Rm,圆心为(0,0),同时有一个圆形范围圆心 ...
- HDU 4793 Collision (2013长沙现场赛,简单计算几何)
Collision Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 5114 扩展欧几里得
题目大意:给你两个球的坐标 他们都往(1, 1)这个方向以相同的速度走,问你他们在哪个位置碰撞. 思路:这种题目需要把x方向和y方向分开来算周期,两个不同周期需要用扩展欧几里得来求第一次相遇. #in ...
- HDU 4793 Collision (解二元一次方程) -2013 ICPC长沙赛区现场赛
题目链接 题目大意 :有一个圆硬币半径为r,初始位置为x,y,速度矢量为vx,vy,有一个圆形区域(圆心在原点)半径为R,还有一个圆盘(圆心在原点)半径为Rm (Rm < R),圆盘固定不动,硬 ...
- HDU 4793 Collision --解方程
题意: 给一个圆盘,圆心为(0,0),半径为Rm, 然后给一个圆形区域,圆心同此圆盘,半径为R(R>Rm),一枚硬币(圆形),圆心为(x,y),半径为r,一定在圆形区域外面,速度向量为(vx,v ...
- 2014ACM/ICPC亚洲区北京站题解
本题解不包括个人觉得太水的题(J题本人偷懒没做). 个人觉得这场其实HDU-5116要比HDU-5118难,不过赛场情况似乎不是这样.怀疑是因为老司机带错了路. 这套题,个人感觉动态规划和数论是两个主 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C.Ray Tracing (模拟或扩展欧几里得)
http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing 数学
C. Ray Tracing 题目连接: http://codeforces.com/contest/724/problem/C Description oThere are k sensors lo ...
随机推荐
- ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2 JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):
eclipse中进行java debug调试时出现上述问题. solution:请在代码最后加入以下语句:System.exit(0)即可.
- Sublime Text 3 搭建 React.js 开发环境
sublime有很强的自定义功能,插件库很庞大,针对新语言插件更新很快,配合使用可以快速搭建适配语言的开发环境. 1. babel 支持ES6, React.js, jsx代码高亮,对 JavaScr ...
- Android 打开闪光灯(手电筒)
package com.example.openBackLight; import android.app.Activity; import android.hardware.Camera; impo ...
- struts2配置文件中action的name属性
struts2配置文件中action的name属性的第一个字符不要加斜杠 <action name="see" class="baoxiuManage_seeAct ...
- SaaS系列介绍之十四: SaaS软件开发分析
1 引言 真正的问题,不是电脑是否具备思考能力,而是人类是否具备这种能力 ________B.F.Skinner<计算机科学> SaaS模式不同于传 ...
- hdu 1002 java 大数相加
package Main; //import java.io.InputStream; import java.math.BigDecimal; import java.util.Scanner; p ...
- LR_问题_无法使用LR的Controller,提示缺少license
问题描述 无法使用LR的Controller,提示缺少license 问题解决 使用开始->所有程序->HP LoadRunner->loadrunner,在打开界面的左上角选择co ...
- QEvent大全,有中文解释
简述 QEvent 类是所有事件类的基类,事件对象包含事件参数. Qt 的主事件循环(QCoreApplication::exec())从事件队列中获取本地窗口系统事件,将它们转化为 QEvents, ...
- iOS iOS7越狱
1.使用盘古越狱工具 (或者PP助手) 2.越狱成功后需要安装Apple File Conduit “2”,用于替代afc2add插件 3.安装AppSync插件 (绕过系统验证,随意安装.运行破解的 ...
- Android关于实现EditText中加多行下划线的的一种方法
1. 重写EditText public class LinedEditText extends EditText { private Paint linePaint; private float m ...