I - Long Distance Racing(第二季水)
Description
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
太水,不解释
#include<iostream>
using namespace std;
char s[];
int main()
{
int m,t,u,f,d,k=,a;
cin>>m>>t>>u>>f>>d;
for(int i=;i<t;i++)cin>>s[i];
int i;
for(i=;i<t;i++){
if(s[i]=='u'||s[i]=='d')k+=u+d;
else k+=*f;
if(k>m)break;
a=k;
}
cout<<i<<endl;
//system("pause");
return ;
}
I - Long Distance Racing(第二季水)的更多相关文章
- F - The Fun Number System(第二季水)
Description In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight o ...
- D - Counterfeit Dollar(第二季水)
Description Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are t ...
- S - 骨牌铺方格(第二季水)
Description 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数. 例如n=3时,为2× 3方格,骨牌的铺放方案有三种, ...
- R - 一只小蜜蜂...(第二季水)
Description 有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数. 其中,蜂房的结构如下所示. ...
- Y - Design T-Shirt(第二季水)
Description Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA ...
- N - Robot Motion(第二季水)
Description A robot has been programmed to follow the instructions in its path. Instructions for the ...
- B - Maya Calendar(第二季水)
Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old ...
- T - 阿牛的EOF牛肉串(第二季水)
Description 今年的ACM暑期集训队一共有18人,分为6支队伍.其中有一个叫做EOF的队伍,由04级的阿牛.XC以及05级的COY组成.在共同的集训生活中,大家建立了深厚的 ...
- E - Number Sequence(第二季水)
Description A single positive integer i is given. Write a program to find the digit located in the p ...
随机推荐
- jsp页面获取服务器时间
Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MON ...
- linux 系统下java开发环境的配置
在安装之前,确保你的linux系统下有 jdk,jboss等相关软件 一.配置JDK环境变量 步骤: 解压缩JDK文件: unzip jdk1.6.0_31.zip 目录下显示文件夹jdk1.6.0_ ...
- Spark集群搭建简要
Spark集群搭建 1 Spark编译 1.1 下载源代码 git clone git://github.com/apache/spark.git -b branch-1.6 1.2 修改pom文件 ...
- 整不明白Jquery的问题
最近写个GridView,由于不是很熟悉javascript,用jquery实现后,发现下面设置左右表行高的代码如果不把行保存在$tr1,$tr2中再设置css,速度非常慢,300行50列左右的数据得 ...
- 居然因为交换错了好几把。。。。,还有坑点是num1可以大于num2
完数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- Planner – 项目管理软件
http://www.appinn.com/planner/ Planner 是一款开源.易用.跨平台的项目管理软件.@appinn 二猪用了 OpenProject 几年,现在已经受够了它的各种 ...
- QT自定义窗口(模拟MainWindow)
在这里自定义窗口是通过继承于QFrame,内部分为上下两部分,上半部分就是标题栏,下面是窗口的具体内容.上下两部分通过布局固定位置.最后窗口的各种鼠标拖动,缩放,等操作通过添加鼠标事件来完成一个窗口的 ...
- C# Assembly类_反射
System.Reflection.Assembly类是一个比较常用到的类,在反射中就经常用到. 由于这个类实在有太多的字段.属性与方法.实在不想将一个个属性方法从MSDN复制出来然后逐个属性.方法敲 ...
- 在 ASP.NET MVC 项目中使用 WebForm、 HTML
原文地址:http://www.cnblogs.com/snowdream/archive/2009/04/17/winforms-in-mvc.html ASP.NET MVC和WebForm各有各 ...
- poj 2299 Ultra-QuickSort(归并排序或是bit 树+离散化皆可)
题意:给一个数组,计算需要的冒泡排序的次数,元素个数很大,不能用n^2的冒泡排序计算. 解析:这题实际上就是求逆序对的个数,可以用归并排序的方法,我这里用另一种方法写,bit树+离散化.由于元素的值可 ...