UVALive 6835 Space Golf(物理题)
2015-12-08 01:13
477 查看
题意:
n≤10个障碍物,一个球从起点弹到终点距离为d≤10000,反弹次数b≤15,重力g=1
不计中间过程的能量损失,问可以越过所有障碍物最小的初速度是多少?
分析:
由于反弹次数很小,我们可以考虑枚举反弹次数,由于障碍物个数也很少我们也可以枚举障碍物
假设所求的速度为v,vx=vcosθ,vy=vsinθ,根据水平时间与竖直时间相等可知,12lvx=vyg
可得l=2vxvyg=v2⋅2sinθcosθg=v2⋅sin2θg ①
对于相同的速度的情况下,θ=45度时,l取到最大值为最优,所以出射角应该≥45度
对于每个反弹次数,我们可以得到球运动的抛物线的宽度l=d/(i+1)
对于一个包含障碍物的抛物线周期,我们知道三个点(0,0),(x,hi),(l,0),其中x是所在抛物线周期的pi位置
根据抛物线两根式y=a(x−x1)(x−x2)=>y=ax(x−l),解得:a=hi/(x∗(x−l))
求导y=ax(x−l)得到抛物线的斜率方程y′=2ax−al,代入x=0得,tanθ=−al,即θ=atan(−al) ②
由①变形得,v2=lgsin2θ,再由②即可算出v2
问题解决,不要忘记特判碰到障碍物的情况
代码:
n≤10个障碍物,一个球从起点弹到终点距离为d≤10000,反弹次数b≤15,重力g=1
不计中间过程的能量损失,问可以越过所有障碍物最小的初速度是多少?
分析:
由于反弹次数很小,我们可以考虑枚举反弹次数,由于障碍物个数也很少我们也可以枚举障碍物
假设所求的速度为v,vx=vcosθ,vy=vsinθ,根据水平时间与竖直时间相等可知,12lvx=vyg
可得l=2vxvyg=v2⋅2sinθcosθg=v2⋅sin2θg ①
对于相同的速度的情况下,θ=45度时,l取到最大值为最优,所以出射角应该≥45度
对于每个反弹次数,我们可以得到球运动的抛物线的宽度l=d/(i+1)
对于一个包含障碍物的抛物线周期,我们知道三个点(0,0),(x,hi),(l,0),其中x是所在抛物线周期的pi位置
根据抛物线两根式y=a(x−x1)(x−x2)=>y=ax(x−l),解得:a=hi/(x∗(x−l))
求导y=ax(x−l)得到抛物线的斜率方程y′=2ax−al,代入x=0得,tanθ=−al,即θ=atan(−al) ②
由①变形得,v2=lgsin2θ,再由②即可算出v2
问题解决,不要忘记特判碰到障碍物的情况
代码:
// // Created by TaoSama on 2015-12-07 // Copyright (c) 2015 TaoSama. All rights reserved. // //#pragma comment(linker, "/STACK:1024000000,1024000000") #include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <set> #include <vector> using namespace std; #define pr(x) cout << #x << " = " << x << " " #define prln(x) cout << #x << " = " << x << endl const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7; const double PI = acos(-1), EPS = 1e-8; int sgn(double x) { return x < -EPS ? -1 : x < EPS ? 0 : 1; } int d, n, b; int p[15], h[15]; double solve(int b) { double l = 1.0 * d / (b + 1), maxv = 0; for(int i = 1; i <= n; ++i) { double x = fmod(p[i], l); if(sgn(x) == 0) return 1e20; //collision double a = h[i] / x / (x - l), k = -a * l; double ang = max(atan2(k, 1), PI / 4); // >= 45; maxv = max(maxv, l / sin(2 * ang)); } return maxv; } int main() { #ifdef LOCAL freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin); // freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout); #endif ios_base::sync_with_stdio(0); while(scanf("%d%d%d", &d, &n, &b) == 3) { for(int i = 1; i <= n; ++i) scanf("%d%d", p + i, h + i); double ans = 1e20; for(int i = 0; i <= b; ++i) ans = min(ans, solve(i)); printf("%.5f\n", sqrt(ans)); } return 0; }
相关文章推荐
- PAT-天梯赛习题集-L3-013-非常弹的球
- Concurrency In Golang
- 每次使用都要去Google的基础知识--.lib与.dll
- 每次使用都要去Google的基础知识--.lib与.dll
- HD 1533 Going Home(最小费用最大流模板)
- Category和Protocol笔记 by STP
- [Golang] groupcache的简单例子
- GoEasy在web端推送及接收
- django的i18n
- Category中的属性
- MONGO集群搭建
- Forward Algorithm
- [Golang]优秀开源库剖析
- django分页实现
- google map 根据坐标点自动缩放
- Intent中的四个重要属性——Action、Data、Category、Extras
- 解决Toast不显示问题 Toast invisible to user . go ahead
- Google Guava 常用功能
- go语言 defer 你不知道的秘密!
- Go语言使用PostgreSQL数据库