poj 3672 Long Distance Racing
2016-01-30 11:32
204 查看
<span style="font-size: 18pt; font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">Description</span>
Bessie is training for her next race by running on a path that includes hills so that she will be prepared for any terrain. She has planned a straight path and wants to run as far as she can -- but she must be back to the farm within M seconds (1
≤ M ≤ 10,000,000).
The entire path she has chosen is T units (1 ≤ T ≤ 100,000) in length and consists of equal-length portions that are uphill, flat, or downhill. The input data describes path segment i with a single character Si that is u, f,
or d, indicating respectively uphill, flat, or downhill.
Bessie takes U seconds (1 ≤ U ≤ 100) to run one unit of uphill path, F (1 ≤ F ≤ 100) seconds for a unit of flat path, and D (1 ≤ D ≤ 100) seconds for a unit of downhill path. Note that, when returning
home, uphill paths become downhill paths and downhill paths become uphill paths.
Find the farthest distance Bessie can get from the farm and still make it back in time.
Input
* Line 1: Five space-separated integers: M, T, U, F, and D
* Lines 2..T+1: Line i+1 describes path segment i with a single letter: Si
Output
* Line 1: A single integer that is the farthest distance (number of units) that Bessie can get from the farm and make it back in time.
Sample Input
13 5 3 2 1 u f u d f
Sample Output
3
这道题比较简单;
直接将去的路程和返回的路程一起算就行了;
</pre><pre name="code" class="cpp">#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<string> using namespace std; char s[1000005]; int main() { int M,T,U,F,D; scanf("%d %d %d %d %d",&M,&T,&U,&F,&D); int sum=0,t=0; for(int i=0;i<T;++i) { scanf(" %c",&s[i]); } for(int i=0;i<T;++i) { if(t>=M) break; if(s[i]=='f') { t+=2*F; if(t<=M) ++sum; } else if(s[i]=='u'||s[i]=='d') { t+=U+D; if(t<=M) ++sum; } } printf("%d\n",sum); return 0; }
相关文章推荐
- form不提交问题
- iOS 控制器的生命周期
- winform程序控制面板中卸载显示图标
- tkinter的GUI设计:界面与逻辑分离(三)-- 多页面
- 如何查看R中可获取的数据集有哪些?
- Linux: SYN攻击原理及处理
- spring新版官网下载JAR包方法
- RestTemplate
- android屏幕适配——图片
- 单元测试框架AndroidTestCase
- jquery 展开折叠菜单
- UML
- 转---推荐系统(资料大全) 此博文包含图片 (2014-04-11 09:14:00)
- 辨析取模运算与取余运算
- ASP.NET Core 1.0基础之依赖注入
- 杭电1009
- 关于新浪sae云空间和SVN版本控制
- Delphi GDI对象之绘制位图
- React Native 中文版
- Android 时间控件1.DatePicker