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. 判断输入的数是否为数字,不使用isNaN

    虽然不使用 isNaN ,但使用了 Math 的一些方法. <!-- Author: XiaoWen Create a file: 2016-12-08 11:14:34 Last modifi ...

  2. 更新日志 - fir.im 主题壁纸来了

    fir.im 产品开发团队最近主要在优化应用管理后台和 BugHD 后台,新版应用管理后台很快会与大家见面. 本周其他更新内容简单概述如下: 1.fir.im 工具页添加壁纸主题包 有很多用户很喜欢 ...

  3. Codeforces Round #379 (Div. 2) 总结分享

    前言 初入acm的新手,打算在cf混.这几天没有比赛,就做了个最新的Virtual participation.虽然说div2比较简单,但还是被虐得体无完肤...Orz.两个小时,共6道题.最后只AC ...

  4. hashcode详解

    序言 写这篇文章是因为在看hashMap源码时遇到有什么hashcode值,然后就去查,脑袋里面是有映像的,不就是在Object中有equals和hashcode方法嘛,这在学java基础的时候就遇到 ...

  5. android: 使用前台服务

    9.5.1    使用前台服务 服务几乎都是在后台运行的,一直以来它都是默默地做着辛苦的工作.但是服务的系统 优先级还是比较低的,当系统出现内存不足的情况时,就有可能会回收掉正在后台运行的服 务.如果 ...

  6. git 创建分支并切换

    git checkout -b fix/base //创建分支 git branch -av 查看所有分支 git checkout master //切换分支

  7. 给同为.NET开发者普及一点Oracle数据库经验

    前段时间,因为要给自己开发的搜易站内搜索引擎增加Oracle数据库的支持,所以学习了下Oracle的基础知识,发现使用方式跟MYSQL,MSSQL等数据库的思维有很大的不同,总结一下几点不同,希望给初 ...

  8. 九宫格抽奖HTML+JS版

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  9. js计时器 + asp 计时器

    JS: <script type="text/javascript"> ; function starts() { ) { alert('已经开启了实时监控!') re ...

  10. leveldb - 并发写入处理

    在并发写入的时候,leveldb巧妙地利用一个时间窗口做batch写入,这部分代码值得一读: Status DBImpl::Write(const WriteOptions& options, ...