【题目链接】:http://codeforces.com/problemset/problem/29/B

【题意】



一辆车;

让从A开到B;

然后速度是v;

(只有在信号灯前面才能停下来..否则其他时候只能维持v的速度)

(如果在红绿灯前,刚好从绿灯变成红灯,不能走,但如果从红灯变成绿灯,则可以走)

告诉你A到信号灯的距离l,以及A、B之间距离d;

以及绿灯红灯交替的时间;g和r;

问你从A到B需要花费多少时间;

【题解】



一开始ans=d/v;

看看到达信号灯的时间是不是整数;

不是整数的话;

则不可能刚好遇到绿灯和红灯的转换;->普通处理就好;

(这里的普通处理就是说,到达信号灯时如果是绿灯就不用额外增加时间,是红灯的话,就增加一个等红灯的时间);

如果是整数的话;

看看是不是遇到红灯和绿灯的转换处;

是的话,如果是红灯变成绿灯,不增加额外时间;

绿灯变红灯的话,额外增加红灯的等待时间;

如果不是绿灯和红灯的转换出;还是普通处理;



【Number Of WA】



3



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110; int l,d,v,g,r;
double ans,t1;
int sta; void pt(){
double now = g;
sta = 1;
while (now+1e-6<t1){
if (sta==1)
now+=r;
else
now+=g;
sta^=1;
}
if (sta==0){
ans+=now-t1;
}
} int main(){
//Open();
Close();//scanf,puts,printf not use
//init??????
cin >> l >> d >> v >> g >> r;
ans = (l*1.0)/v;
//cout << fixed << setprecision(10)<<ans<<endl;
t1 = (d*1.0)/v;
if (d%v!=0){
//cout <<t1<<endl;
pt();
}
else{
int k = d/v;
int time = g,sta = 1;
while (time!=k && time < 1500){
if (sta==1)
time+=r;
else
time+=g;
sta^=1;
}
if (time==k){
if (sta==1){
ans+=r;
}
}
else
pt();
}
cout << fixed << setprecision(10)<<ans<<endl;
return 0;
}

【codeforces 29B】Traffic Lights的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. 小程序全局状态管理,在页面中获取globalData和使用globalSetData

    GitHub: https://github.com/WozHuang/mp-extend 主要目标 微信小程序官方没有提供类似vuex.redux全局状态管理的解决方案,但是在一个完整的项目中各组件 ...

  2. Vue学习之路第八篇:事件修饰符

    学习准备: ①.顾名思义,“事件修饰符”那么肯定是用来修饰事件,既然和事件有关系,那么肯定和“v-on”指令(也可简写为:@)有关系了. ②.事件修饰符有以下几类: .stop:阻止冒泡 .preve ...

  3. JS中的异步

    Hello,日常更新的我“浪”回来了!!! JS中有三座高山:异步和单线程.作用域和闭包.原型原型链 今天“浪”的主题是JS中的异步和单线程的问题. 主要从这三个方面入手 一.什么是异步(与同步作比较 ...

  4. Python中的itertools.product

    例子1:import itertoolsa = itertools.product([1,2,3],[100,200])print(a)for item in itertools.product([1 ...

  5. python异常处理,多线程,多进程

    什么是异常? 异常即是一个事件,该事件会在程序执行过程中发生,影响了程序的正常执行. 一般情况下,在Python无法正常处理程序时就会发生一个异常. 异常是Python对象,表示一个错误. 当Pyth ...

  6. django-3-模板变量,过滤器,静态文件的引用

    <<<模板变量>>> (1)定义视图函数 通过context传递参数来渲染模板,context要是个字典 当模板变量为可调用对象的时候,函数不传递参数 (2)配置模 ...

  7. Golang-import-introduce

    本文主要讲解golang中import关键字的用法 import( "fmt" ) //然后在代码里面可以通过如下的方式调用 fmt.Println("hello wor ...

  8. WinServer-IIS-js无法加载问题

    IIS中无法加载JS文件错误 尝试下面的几种解决方法,一起用

  9. C#-WebService基础02

    WebService WSDL是web service的交换格式 跨平台数据交互 什么是web服务 SOA 面向服务的体系结构  service-Oriented Architecture Servi ...

  10. POJ-1785-Binary Search Heap Construction(笛卡尔树)

    Description Read the statement of problem G for the definitions concerning trees. In the following w ...