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 ...
随机推荐
- 7.Vue-Quill-Editor图片插入自定义
Vue-Quill-Editor图片插入自定义 前言: 因为在项目中前端采用了Vue来实现,正好用到了富文本编辑器这一块,于是,经过技术上的选择,决定使用Vue-Quill-Editor. 使用的过程 ...
- SpringBoot非官方教程 | 终章:文章汇总
转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot-all/ 本文出自方志朋的博客 SpringBo ...
- Tomcat服务器的介绍、安装配置
[1] Tomcat服务器的介绍 1.是一个免费的.开饭源代码的Servlet服务器,目前非常流行. 2.Tomcat服务器是Apache软件基金会的一个顶级项目,由Apache.Sun等公司共同开发 ...
- ABAP术语-Object Name
Object Name 原文:http://www.cnblogs.com/qiangsheng/archive/2008/03/05/1091092.html An object name is a ...
- ABAP术语-BW (Business Information Warehouse)
BW (Business Information Warehouse) 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/14/1037761. ...
- MyEclipse格式化JSP代码,其中Javascript无法格式化的原因
MyEclipse格式化JSP代码,其中Javascript无法格式化的原因: 可能是JSP页面代码有错误的地方,而且可能是一个很微小的错误,比如多写了一个标点符号,这个需要仔细检查,包括HTML.C ...
- CentOS7下PHP7.2安装redis扩展
1.安装phpize(存在忽略) yum install php-devel 2.下载扩展源码包,直接用wget,一般放在 /usr/local/src wget https://github.com ...
- js实现前端的搜索历史记录
最近在对接前台页面(WEB端)时,产品要求需记录下客户的搜索记录,我们是前后台完全分离的项目,根本不能保存的session域中,没办法,虽然作为后台开发,遇到需求就自己研究了一通,先看一下最终效果图, ...
- 主流浏览器内核,以及CSS3前缀识别码
现在国内常见的浏览器有:IE.Firefox.QQ浏览器.Safari.Opera.Google Chrome.百度浏览器.搜狗浏览器.猎豹浏览器.360浏览器.UC浏览器.遨游浏览器.世界之窗浏览器 ...
- 我所用过的nginx的功能
前言 当我们提起集群时,一般所用的插件就是nginx.nginx功能如今越来越完善.第三方模块也多如牛毛,在此,总结一下不牵扯第三方模块所具有的功能. 基本功能 反向代理 负载均衡 HTTP服务器(动 ...