Traffic Lights
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the following r seconds the red light is on, then again the green light is on for the g seconds, and so on.

The car can be instantly accelerated from 0 to v and vice versa, can instantly slow down from the v to 0. Consider that it passes the traffic lights at the green light instantly. If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it. But if it approaches the traffic lights at the moment when the green light has just turned on, it can move. The car leaves point A at the time 0.

What is the minimum time for the car to get from point A to point B without breaking the traffic rules?

提示:

1.注意“If the car approaches the traffic lights at the moment when the red light has just turned on, it doesn't have time to pass it”。

2.只要不是等待绿灯,都全速行驶

AC  Code:

 #include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std; int main()
{
double l, d, v, g, r;
double ans;
const double eps = 1e-;
while(cin >> l >> d >> v >> g >> r)
{
int t = d / v / (g + r);
double a = d / v - t * (g + r);
if(fabs(a - g) < eps)
ans = l / v + r;
else if(a < g)
ans = l / v;
else
ans = g + r - a + l / v;
printf("%.8lf\n", ans);
}
return ;
}

Traffic Lights的更多相关文章

  1. 快速切题 sgu103. Traffic Lights 最短路 难度:1

    103. Traffic Lights Time limit per test: 0.25 second(s)Memory limit: 4096 kilobytes input: standardo ...

  2. sgu 103 Traffic Lights 解题报告及测试数据

    103. Traffic Lights Time limit per test: 0.25 second(s) Memory limit: 4096 kilobytes 题解: 1.其实就是求两点间的 ...

  3. POJ1158 城市交通Traffic lights IOI 1999 (最短路)

    POJ1158 城市交通Traffic lights IOI 1999 (最短路) (1) 问题描述(probolem) 在d城里交通的安排不同寻常,城中有路口和路口之间的道路,再任意两个不同的路口之 ...

  4. sgu 103 Traffic Lights

    这道题难得不是算法,而是处理. 题意就是让你求最短路,只有当两个点在某一秒颜色相同时,这条边才可以通行,输入首先给你 起点和终点, 然后给你 点数和边数, 接下来 n 行 初始颜色,初始颜色持续时间, ...

  5. Traffic Lights - SGU 103(最短路)

    题目大意:有一个城市的路线图,有N个交叉点,每两个交叉点之间只有一条路,现在想从交点u去交点v,不过这个路的交通比较特别,每个路都有一个交通灯,灯有两种颜色,蓝色和紫色,例如一条路线在交点s,t之间, ...

  6. SGU 103.Traffic Lights(最短路)

    时间: 0.50 second(s) 空间: 4096 kilobytes 输入: 标准输入 输出: 标准输出 Dingiville 城市的交通规则非常奇怪,城市公路通过路口相连,两个不同路口之间最多 ...

  7. TRAFFIC LIGHTS POJ 1158

    题目大意: 在Dingilville 城市安排是一种不同寻常的方式,每个交叉路口有一条道路连接,一条道路最多连接两个不同的交叉路口.每个交叉路口不能连接他自己.道路旅行一端到另一端的时间是相同的,任何 ...

  8. 【codeforces 29B】Traffic Lights

    [题目链接]:http://codeforces.com/problemset/problem/29/B [题意] 一辆车; 让从A开到B; 然后速度是v; (只有在信号灯前面才能停下来..否则其他时 ...

  9. SGU 103 Traffic Lights【最短路】

    题目链接: http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=16530 题意: 给定每个点最初的颜色,最初颜色持续时间,以 ...

随机推荐

  1. c#访问http接口的"编码"问题

    记一次访问http数据接口的爬坑经历,一般访问一个http接口. 无非就是这么几行代码: HttpWebRequest request = (HttpWebRequest)WebRequest.Cre ...

  2. paip.自定义java 泛型类与泛型方法的实现总结

    paip.自定义java 泛型类与泛型方法的实现总结 ============泛型方法     public static <atiType,retType> retType reduce ...

  3. jQuery/javascript实现网页注册的表单验证

    <html> <head> <meta charset="utf-8"> <title>注册表单验证</title> & ...

  4. jquery parent和parents的区别

    从字面上不难看出parent是指取得一个包含着所有匹配元素的唯一父元素的元素集合.parents则是取得一个包含着所有匹配元素的祖先元素的元素集合(不包含根元素).可以通过一个可选的表达式进行筛选可以 ...

  5. [推荐] kylinPET是一款功能强大的性能测试工具

    [推荐] kylinPET是一款功能强大的性能测试工具 官方网站: http://www.kylinpet.com/

  6. BeginInvoke与EndInvoke方法解决多线程接收委托返回值问题

    BeginInvoke与EndInvoke方法解决多线程接收委托返回值问题 原文:http://www.sufeinet.com/thread-3707-1-1.html      大家可以先看看我上 ...

  7. RPM -U 升级机制探索

    今天被RPM升级机制狠狠的阴了一把,差点没过来,趁着热乎赶紧记录下来,已被后用. RPM包有升级机制(Upgrade), 使用-U 参数.这点我之前略有耳闻,知道的并不详细. 先说说案例:半年前我们r ...

  8. SVO实时全局光照优化(里程碑MK0):Sparse Voxel Octree based Global Illumination (SVO GI)

    完全自主实现,bloat-free.再次声明,这不是UE.U3D.CE.KlayGE! 老规矩,先贴图.后面有时间再补充描述. 1. 支持多跳间接全局光照2. 支持vxao/so.vxdiff/spe ...

  9. <[你在荒废时间的时候别人都在拼命!]>

    如果我在这里退缩了,那么再也不可能前进 当人有了目标的时候,就会有拼命努力的动力. 当一个人真的掌握了一些东西的时候,才会觉得踏实,这就是所谓的内涵. 人生其实就是这样一步步走过去的.付出总有回报,回 ...

  10. js实现hash

    由于项目中用到了hash,自己实现了一个. Hash = function () { } Hash.prototype = { constructor: Hash, add: function (k, ...