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:

  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <map>
  5. #include <vector>
  6. #include <cstdio>
  7. #include <cmath>
  8. #include <cstring>
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. double l, d, v, g, r;
  14. double ans;
  15. const double eps = 1e-;
  16. while(cin >> l >> d >> v >> g >> r)
  17. {
  18. int t = d / v / (g + r);
  19. double a = d / v - t * (g + r);
  20. if(fabs(a - g) < eps)
  21. ans = l / v + r;
  22. else if(a < g)
  23. ans = l / v;
  24. else
  25. ans = g + r - a + l / v;
  26. printf("%.8lf\n", ans);
  27. }
  28. return ;
  29. }

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. Seo的几个境界

    Seo的境界 第一层,弄些关键词排名上去. 是的,大部分人理解的Seoer,就到此为止 这里有技巧若干若干.很值得一些人去卖弄. 第二层,大量广泛的收录,很好的pr值 恭喜您,把握搜索长尾, 这种不显 ...

  2. paip.提升安全性----Des加密 java php python的实现总结

    paip.提升安全性----Des加密 java php python的实现总结 ///////////    uapi         private static String decryptBy ...

  3. spring源码 — 一、IoC容器初始化

    IoC容器初始化 注意:本次的spring源码是基于3.1.1.release版本 容器:具有获取Bean功能--这是最基本功能,也是BeanFactory接口定义的主要行为,在添加了对于资源的支持之 ...

  4. mac上安装homebrew

    1:关于homebrew下载地址 homebrew下载地址网上版本很多:我用了几个都是显示 404 bad request 如图:均无法现在 有一个网址会给出最新的 安装地址: the URL is: ...

  5. openCV_java 图像二值化

    较为常用的图像二值化方法有:1)全局固定阈值:2)局部自适应阈值:3)OTSU等. 局部自适应阈值则是根据像素的邻域块的像素值分布来确定该像素位置上的二值化阈值.这样做的好处在于每个像素位置处的二值化 ...

  6. ubuntu 16.04 有道词典

    依赖环境 sudo apt install \ python3-pyqt5 \ python3-requests \ python3-xlib \ python3-pil \ tesseract-oc ...

  7. Spark RDD解密

    1.  基于数据集的处理: 从物理存储上加载数据,然后操作数据,然后写入数据到物理设备; 基于数据集的操作不适应的场景: 不适合于大量的迭代: 不适合交互式查询:每次查询都需要对磁盘进行交互. 基于数 ...

  8. Flipping elements with WPF

    http://yichuanshen.de/blog/2010/11/13/flipping-elements-with-wpf/ Have you already seen ForgottenTim ...

  9. python use dom to write xml file

    #encoding:utf-8 ''' write xml in dom style ''' from xml.dom.minidom import Document doc = Document() ...

  10. Windows Tomcat7.0 安装 Solr

    准备工作 1.下载Tomcat7.0 ,apache-tomcat-7.0.67.exe,安装目录如下:C:\workspace\Tomcat7.0\ 2.下载Solr 5.2,solr-5.2.0. ...