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(第二季水)的更多相关文章

  1. 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 ...

  2. D - Counterfeit Dollar(第二季水)

    Description Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are t ...

  3. S - 骨牌铺方格(第二季水)

    Description          在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.         例如n=3时,为2× 3方格,骨牌的铺放方案有三种, ...

  4. R - 一只小蜜蜂...(第二季水)

    Description          有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数.         其中,蜂房的结构如下所示.     ...

  5. Y - Design T-Shirt(第二季水)

    Description Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA ...

  6. N - Robot Motion(第二季水)

    Description A robot has been programmed to follow the instructions in its path. Instructions for the ...

  7. B - Maya Calendar(第二季水)

    Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old ...

  8. T - 阿牛的EOF牛肉串(第二季水)

    Description          今年的ACM暑期集训队一共有18人,分为6支队伍.其中有一个叫做EOF的队伍,由04级的阿牛.XC以及05级的COY组成.在共同的集训生活中,大家建立了深厚的 ...

  9. E - Number Sequence(第二季水)

    Description A single positive integer i is given. Write a program to find the digit located in the p ...

随机推荐

  1. 【转】Redis安装整理(window平台和Linux平台)

    原文连接:http://zheng12tian.iteye.com/blog/1471726 原文作者:zheng12tian 转载注明以上信息! window平台Redis安装 redis wind ...

  2. Pubwin服务端重装(安装)教程

    此博文已移至爬不稳独立博客:www.pubwin2009.net传送门:http://www.pubwin2009.net/index.php/post/6.html 一,卸载原来服务端和数据库. 1 ...

  3. information_schema.partitions 学习

    1.partitions 表中的常用列说明: 1.table_schema:表所在的数据库名 2.table_name:表名 3.partition_method:表分区采用的分区方法 4.parti ...

  4. Resharper使用

    Resharper进阶一:简要介绍 官方下载地址下载地址  注册码: 用户名: User 注册码:D9d09DSYJel9IyuDU4btAQwZcbLugUad 面对这样一个问题:为什么.net能够 ...

  5. setPixel抛出java.lang.IllegalStateException

    原来,从ImageView里读取的Bitmap,或者加载drawable里的图片资源,返回的都是一个immutalbe的bitmap,所以不能用setpixels 必须采取类似Bitmap bmp = ...

  6. 弄明白Android 接口回调机制

    以前对于这个机制理解不够深刻,现在重新整理下思路. 一.建模 我理解的接口回调就是,我这个类实现了一个接口里的方法doSomething,然后注册到你这里,然后我就去做别的事情去了,你在某个触发的时机 ...

  7. 杭电1010(dfs + 奇偶剪枝)

    题目: The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked ...

  8. Number of Containers(数学) 分类: 数学 2015-07-07 23:42 1人阅读 评论(0) 收藏

    Number of Containers Time Limit: 1 Second Memory Limit: 32768 KB For two integers m and k, k is said ...

  9. What is NicEdit?

    NicEdit - WYSIWYG Content Editor, Inline Rich Text Application   What is NicEdit? NicEdit is a Light ...

  10. Pros and Cons of T4 in Visual Studio 2008

    Oleg Sych - » Pros and Cons of T4 in Visual Studio 2008 Pros and Cons of T4 in Visual Studio 2008 Po ...