UVA 11880 Ball in a Rectangle(数学+平面几何)
Input: Standard Input Output: Standard Output
� There is a rectangle on the cartesian plane, with bottom-left corner at (0,0) and top-right corner at (L,W). There is a ball centered at (x, y), with radius=R, shown below

At time 0, the ball starts to move along a ray with polar angle a (the angle from positive x-axis to the ray, rotating counter-clockwise). When hitting the rectangle boundary, the reflex angle always equals to the incidence angle. The ball's velocity is always v (i.e. it never changes when hitting the rectangle). Where is the center of the ball at time s?
Input
There will be at most 25 test cases, each contains a line with 8 integers L,W,x,y,R,a,v,s (100L,W
109, 1
R
5, R
x
L - R, R
y
W - R, 0
a < 360, 1
v, s
109), as stated above. The input terminates with L= W = x = y = R = a = v = s = 0, which should not be processed.
Output
For each test case, output a line containing two floating-point numbers x, y, rounded to two decimal points, indicating that the center of ball will be at (x, y) at time s.
题目大意:一个半径为R的圆以一个角度α和恒定速度v在一个L*W的场地中乱撞,撞墙后反射的方向与镜面反射相同。
思路:首先,一个圆在[0,L]、[0,W]里乱撞,相当于一个这个圆的圆心在[R, L-R], [R, W-R]里乱撞。答案也是要圆心,那么只考虑圆心即可。之后,速度是恒定的,横向速度和纵向速度也是不变的,假设场地为无限大,那么我们一开始就可以算出最终坐标(理论上来说极限数据会爆double的精度,但是AC了,我就不管了……要是真WA了我们可以试试long double……)。然后x、y完全可以分开算,他们之间一点影响都木有。于是考虑x,若有一堵墙在L-R处,如果没有墙L我们可以到达xi(超过了L-R),那么有墙我们就会到达2*(L-R) - xi;如果有墙在R,我们可以到达xi(小于R),那么我们就会到达2 * R - xi。不断重复直到xi落在[R, L-R]之间(极限数据这样搞可能会TLE,但是AC了,所以也不管了……)。Y一样搞法,不重复说了。
PS:不要找我要证明我不会,我只能说我觉得这样搞是对的。
代码(19MS):
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL; const double PI = acos(-1.0);
const double EPS = 1e-; LL L, W, x, y, R, a, v, s; int main() {
//cout<<cos(PI/2)<<endl;
while(cin>>L>>W>>x>>y>>R>>a>>v>>s) {
if(L == && W == && x == && y == && R == && a == && v == && s == ) break;
double nx = x + v * cos(PI * a / ) * s, ny = y + v * sin(PI * a / ) * s;
L -= R;
W -= R;
while(R >= nx + EPS || nx - EPS >= L) {
if(R >= nx) nx = * R - nx;
//if(nx >= 20 * L) nx = nx - 20 * L;
if(nx >= L) nx = * L - nx;
}
while(R >= ny + EPS || ny - EPS >= W) {
if(R >= ny) ny = * R - ny;
if(ny >= W) ny = * W - ny;
}
printf("%.2f %.2f\n", nx, ny);
}
}
UVA 11880 Ball in a Rectangle(数学+平面几何)的更多相关文章
- UVA 12378 Ball Blasting Game 【Manacher回文串】
Ball Blasting Game Morteza is playing a ball blasting game. In this game there is a chain of differe ...
- UVA 10780 Again Prime No Time.(数学)
给定两个整数m和n,求最大的k使得m^k是n!的约数 对m质因子分解,然后使用勒让德定理求得n!包含的质数p的阶数,min(b[i] / a[i])即为结果k, 若为0无解 #include<c ...
- UVA 11582 Colossal Fibonacci Numbers!【数学】
大一刚开始接触ACM就买了<算法竞赛入门经典>这本书,当时只能看懂前几章,而且题目也没做,粗鄙地以为这本书不适合自己.等到现在快大三了再回过头来看,发现刘老师还是很棒的! 扯远了... 题 ...
- UVA 11300 Spreading the Wealth (数学推导 中位数)
Spreading the Wealth Problem A Communist regime is trying to redistribute wealth in a village. They ...
- UVA 10217 A Dinner with Schwarzenegger!!!---数学
题目链接: https://cn.vjudge.net/problem/UVA-10217 题目大意: 有若干人排队买电影票,如果某个人的生日与排在他前面的某个人的生日相同,那么他讲中奖.中奖的机会只 ...
- uva 10828 高斯消元求数学期望
Back to Kernighan-RitchieInput: Standard Input Output: Standard Output You must have heard the name ...
- GCD - Extreme (II) UVA - 11426 欧拉函数_数学推导
Code: #include<cstdio> using namespace std; const int maxn=4000005; const int R=4000002; const ...
- 算法笔记_120:蓝桥杯第六届省赛(Java语言B组部分习题)试题解答
目录 1 三角形面积 2 立方变自身 3 三羊献瑞 4 九数组分数 5 饮料换购 6 生命之树 前言:以下试题解答代码部分仅供参考,若有不当之处,还请路过的同学提醒一下~ 1 三角形面积 三角形 ...
- codeforces 691F F. Couple Cover(组合计数)
题目链接: F. Couple Cover time limit per test 3 seconds memory limit per test 512 megabytes input standa ...
随机推荐
- JDBC连接数据库时错误提示的解决方案汇总
今天在连接JDBC时,出现了错误 最开始的URL是这样写的 Connection conn = DriverManager.getConnection("jdbc:mysql://local ...
- update、commit、trancate,delete
update 用于更新表的数据,使用方式为: update table_name set column_name=值 条件 顺便一提:date数据插入更新应该使用 to_date()格式转换函数例如: ...
- Angularjs基础(六)
AngularJS HTML DOM AngularJS为HTML DOM 元素的属性提供了绑定应用数据的指令. ng-disabled指令 ng-disabled指令直接绑定应用数据到HTML的di ...
- BZOJ3277: 串(广义后缀自动机)
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1196 Solved: 478[Submit][Status][Discuss] Descripti ...
- Java分享笔记:Java网络编程--TCP程序设计
[1] TCP编程的主要步骤 客户端(client): 1.创建Socket对象,构造方法的形参列表中需要InetAddress类对象和int型值,用来指明对方的IP地址和端口号. 2.通过Socke ...
- MySQL数据库初识——初窥MySQL
初步了解MySQL基本数据库语言 1.创建一个Mysql数据库 create database database_name: 2.显示所有的Mysql数据库 show databases: 3.使用 ...
- LeetCode-环形链表II
LeetCode-环形链表II 为找到入口点可以用以下方法 使用快慢指针法直到两个指针相遇 头节点处创建一个新的指针,并且向前移动,两个指针相遇处创建一个新的指针,并且向前移动,直到两个指针相遇为入口 ...
- 封装localstorage方法
//封装操作localstorage本地存储的方法 var storage = { //存储 set(key, value) { localStorage.setItem(key, JSON.stri ...
- echarts重新加载动画
echarts重新加载动画 var option1 = area_right_top1.getOption();area_right_top1.clear();area_right_top1.setO ...
- python学习之对象的三大特性
在面向对象程序设计中,对象可以看做是数据(特性)以及由一系列可以存取.操作这些数据的方法所组成的集合.编写代码时,我们可以将所有功能都写在一个文件里,这样也是可行的,但是这样不利于代码的维护,你总不希 ...