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. PHP学习笔记十六【方法】

    <?php //给一个函数传递基本数据类型 $a=90; $b=90.8; $c=true; $d="hello world"; function test1($a,$b,$ ...

  2. OD调试2---TraceMe

    OD调试2---TraceMe 拆解一个Windows程序要比拆解一个DOS程序容易得多,因为在Windows中,只要API函数被使用,想对寻找蛛丝马迹的人隐藏一些东西是比较困难的.因此分析一个程序, ...

  3. java连接sqL2008 数据库实例

    package com.lzw; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSe ...

  4. Qt调用外部程序QProcess通信

    mainwindow.cpp文件: -------------------------------- #include "mainwindow.h" #include " ...

  5. MySQL 初学笔记 ① -- MySQL用户登录权限控制

    1. MySQL 登录 MySQL -u username -p 2. MySQL 创建用户 use mysql //进入mysql 表 INSERT INTO user (Host,User,Pas ...

  6. Excel Aspose.Cells 设置单元格格式 为数字

    Workbook workbook = new Workbook(); //工作簿 Worksheet sheet = workbook.Worksheets[]; //工作表 sheet.Cells ...

  7. Sublime 插件安装

    转http://www.cnblogs.com/Rising/p/3741116.html

  8. Hibernate配置属性

    Hibernate配置属性 属性名 用途 hibernate.dialect 一个Hibernate Dialect类名允许Hibernate针对特定的关系数据库生成优化的SQL. 取值 full.c ...

  9. QT字体的设置

    摘要: QT4.7.0在移植到开发板上的时候,中文支持是必不可少的,如何让QT支持中文,如何制作QT支持的字体文件,如何使QT UI编辑器中的字号与开发板中的字号一致.作者通过实验进行了一一验证. 介 ...

  10. jdk8预览

    原文:http://www.techempower.com/blog/2013/03/26/everything-about-java-8/ 1.接口增强 (1)接口可以定义static方法 java ...