poj 3672

来源:互联网 发布:ipad弹钢琴软件 编辑:程序博客网 时间:2024/04/30 00:05
[NWPU][2014][TRN][1]水题堆
7:30:00
  • Overview
  • Problem
  • Status
  • Rank
  • Discuss
          
E - Long Distance Racing
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status Practice POJ 3672

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 ≤ ≤ 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 uf, or d, indicating respectively uphill, flat, or downhill.

Bessie takes U seconds (1 ≤ ≤ 100) to run one unit of uphill path, F (1 ≤ F ≤ 100) seconds for a unit of flat path, and (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: MT,UF, 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 1ufudf

Sample Output

3

//@auther Yang Zongjun#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#include <string>using namespace std;#define PI acos(-1.0)#define EPS 1e-8const int MAXN = 100005;const int INF = 2100000000;int sum, n, u, f, d;string a[MAXN];int res[MAXN];int main(){//    freopen("C:/Users/Administrator/Desktop/input.txt", "r", stdin);    cin >> sum >> n >> u >> f >> d;    getchar();    for(int i = 0; i < n; i++)    {        getline(cin, a[i]);        //cout << a[i] << endl;    }    int ans = 0;    int t = u + d, cnt = 0;    int maxa = min(t, 2*f);    for(int i = 0; i < n; i++)    {        //cout << a[i][0] << endl;        //if(sum < ans + maxa) break;        if(a[i][0] == 'u' || a[i][0] == 'd')        {            ans += t;res[cnt++] = ans;        }        else if(a[i][0] == 'f')        {            ans += 2*f;res[cnt++] = ans;        }    }    int i;    for(i = 0; i < n; i++)    {        //cout << res[i] << endl;        if(res[i] > sum) break;    }    printf("%d\n", i);    return 0;}


0 0