平常水题
来源:互联网 发布:牛股选股公式源码 编辑:程序博客网 时间:2024/05/16 04:55
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of nvertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109,0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
5 5 1 21 23 14 33 41 4
5.0000000000
Following image describes initial position in the first sample case:
题意:一个人要过马路,从(0,0)点出发到达(0,w)点,人速度的方向垂直于x轴向上,速度最大为u。同时有一辆凸边形的车以垂直于y向左,大小为v的速度行驶。问:在不被车撞到的情况下(在车的边缘不算被撞到),人通过马路需要的最少时间?
解题思路:有两种情况 ①在车的点还没到y轴(也就是x = 0)时,人已经越过车了(也就是说无需等待,人直接就可以以最快速度u通过马路)。
②人先在起点等时间t(车已经走了一段距离了),然后以最大速度u行走,刚好贴着车的点过。用二分得到t。
#include<bits/stdc++.h>using namespace std;double h[10005][3];int slove1(int n,double u,double v){//第一种情况的判断for(int i = 1;i <= n;i++){if(u * h[i][1] < v * h[i][2])return 0;}return 1;//若车的所有点到y轴所需要的时间 >= 人到该点所需要的时间,就符合第一种条件。}int slove2(double mid,int n,double v,double u){//第二种情况for(int i = 1; i <= n;i++){if(h[i][1] / v > h[i][2] / u + mid)return 0;}return 1;//若车的所有点到y轴所需要的时间 <= 人到该点所需要的时间 + 开始在起点等的时间mid //说明这个mid符合条件,再去找有没有更短的时间。}int main(){int n;double w,v,u,l = 0,r = 1e9,mid;scanf("%d %lf %lf %lf",&n,&w,&v,&u);for(int i = 1;i <= n;i++){scanf("%lf %lf",&h[i][1],&h[i][2]);}if(slove1(n,u,v)){//第一种情况printf("%.10lf",w / u);return 0;}while(r - l > 1e-10){//第二种情况(二分)mid = (l + r) / 2;if(slove2(mid,n,v,u)) r = mid; else l = mid;}printf("%.10lf", w / u + mid);}
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题 Educational Codeforces Round 26 C (错误总结)
- 平常人要走平常路?
- 平常水题 — Codeforces Round #415 (Div. 2) B. Summer sell-off (贪心 + 错误总结)
- 50道java编程小题,平常可以拿来练手
- 50道java编程小题,平常可以拿来练手
- 平常整理
- 梯度下降法解(线性回归,LRegression, ANN(神经网络));
- [BZOJ4820] 硬币游戏
- 使用Kotlin开发Android项目(一)
- 十分钟学会Charles抓包(iOS的http/https请求)
- VR技术分享交流
- 平常水题
- 1020. 月饼 (25) Python篇
- RBAC(用户权限管理) 基于角色的访问控制
- 【LeetCode】Find Bottom Left Tree Value 解题报告
- Java面试题全集(下)
- 浅谈路径规划算法之Floyed算法
- centos7 openoffice中文乱码
- Java容器-HashMap和HashTable
- MacroSoft数据集MS-Celeb-1M