ZOJ1104-Leaps Tall Buildings
来源:互联网 发布:c语言的应用领域 编辑:程序博客网 时间:2024/05/16 15:33
It's a bird! It's a plane! It's coming right at us!
Although it sometimes seems like it, Superman can't fly (without a plane). Instead, he makes super-human leaps, especially over tall buildings. Since he never knows when he will need to catch a criminal, he can't register flight paths. To avoid hitting planes, he tries to keep his jumps as low to the ground as he can. Given a city-scape as input, find the angle and velocity of Superman's jump that minimizes his maximum altitude.
Recall that gravity provides an acceleration of 9.8 m/s2 downwards and the formula for Superman's vertical distance from his starting location is d(t)=v t + 0.5 a t2 where v is his initial velocity, a is his acceleration and t is time in seconds since the start of the leap.
Input:
Input consists of a sequence of city-scapes, each of the form
n
0 d1
h2 d2
:
h(n-1) d(n-1)
0 dn
Superman starts at ground level and leaps d1+...+dn metres, landing at ground level and clearing all of the buildings at heights h2 to h(n-1), each with the given widths. n will be at most 100.
Output:
Output is the angle and initial velocity that minimizes the height that Superman attains, both appearing on the same line. The values should be given to two decimal places and be accurate within 0.01 degrees or m/s, as appropriate.
Sample Input:
30 510 50 550 10.520 11.525 1010 150 7
Diagram for Second City-scape
(Not to scale.)
Sample Output:
71.57 15.6567.07 27.16
Source: University of Waterloo Local Contest 1998.06.06
题意:有n个建筑,有一个超人要跳过所有建筑,问最低的高度和初始速度角度
解题思路:二分高度
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;const double pi = acos(-1.0);const double eps = 1e-8;double x[105], y[105];int n, cnt;double v, k;bool check(double h){double v1 = sqrt(2 * 9.8*h);double v2 = x[cnt - 1] / (v1 / 4.9);v = sqrt(v1*v1 + v2*v2);k = 180 * acos(v2 / v) / pi;for (int i = 0; i<cnt; i++){double xx;if (x[i] > (x[cnt - 1] / 2)) xx = x[cnt - 1] - x[i];else xx=x[i];double t = xx / v2;double hh = v1*t - 4.9*t*t;if (hh<y[i]) return 0;}return 1;}int main(){while (~scanf("%d", &n)){double xx = cnt = 0, a, b;for (int i = 1; i <= n; i++){scanf("%lf%lf", &a, &b);x[cnt] = xx; y[cnt++] = a;x[cnt] = xx += b; y[cnt++] = a;}double l = 0, r =1.0*INF;while (r-l>eps){double mid = (l + r) / 2;if (check(mid)) r = mid;else l = mid;}check(r);printf("%lf %lf\n", k, v);}return 0;}
- ZOJ1104-Leaps Tall Buildings
- ZOJ 1104Leaps Tall Buildings
- zoj 1104 Leaps Tall Buildings(超人不会飞- -。。)
- Buildings
- Buildings
- Buildings
- Buildings
- Buildings
- Buildings
- Buildings
- Buildings
- Buildings
- Buildings
- Buildings
- tall tale 吹牛
- HDU Buildings
- HDU2560:Buildings
- HDU4296--Buildings
- POJ2388-Who's in the Middle
- VS2012 配置opencv2.4.9
- MySQL 01 SQL概述
- MySQL 02 数据处理之查询
- 状态管理--Cookie
- ZOJ1104-Leaps Tall Buildings
- PYthon -网络编程—TCP编程
- JS学习之表格的排序简单实例
- 操作系统ucore lab3实验报告
- 剑指offer-面试题47-不用加减乘除做加法
- 如何将 Java Web 项目上传到linux
- 安装Anaconda科学计算包
- Django杂七杂八
- 代码小问题