# 11004: 【原1004】西西弗斯式的命运

### 题目描述

author: 吴杰 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/1004

## Sample Input

13 5 3 2 1
u
f
u
d
f


## Sample Output

3


## BugenZhao's solution

//
// Created by BugenZhao on 2019/3/16.
//
// 线性探测

#include <iostream>

using namespace std;

int main() {
int M, T, U, F, D;
cin >> M >> T >> U >> F >> D;
int ans = 0;
int curr = 0;
for (int i = 0; i < T; ++i) {
char c;
cin >> c;
switch (c) {
case 'u':
case 'd':
curr += U + D;
break;
case 'f':
curr += 2 * F;
break;
}
if (curr > M) {
cout << ans << endl;
return 0;
}
++ans;
}
cout << T << endl;
}


## CallMeInk's solution

#include <iostream>

using namespace std;

int main()
{
int i,m,t,u,f,d;
char ch;
cin >> m >> t >> u >> f >> d;
cin.get();
for(i=1;i<=t;i++)
{
cin.get(ch);
cin.get();
if (ch == 'u' || ch == 'd') m -= (u+d);
else m -= f + f;
if (m < 0)
{
cout << i - 1 << endl;
break;
}
}
return 0;
}


## FineArtz's solution

/* 西西弗斯式的命运 */
#include <iostream>
using namespace std;

int main(){
int m, t, u, f, d;
cin >> m >> t >> u >> f >> d;
int NowTime = 0;
for (int i = 0; i != t; ++i){
case 'u': case 'd':
NowTime = NowTime + u + d;
break;
case 'f':
NowTime += 2 * f;
break;
default:
break;
}
if (NowTime > m){
cout << i << endl;
return 0;
}
}
cout << t << endl;
return 0;
}


## ligongzzz's solution

#include "iostream"
#include "cstdio"
using namespace std;

int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

int M, T, U, F, D;
cin >> M >> T >> U >> F >> D;

int ans = 0;
for (int i = 0, cur_time = 0; i < T; ++i) {
char c;
cin >> c;
if (c == 'u'||c=='d') {
if (cur_time + U + D <= M)
++ans;
cur_time += U + D;
}
else {
if (cur_time + 2 * F <= M)
++ans;
cur_time += 2 * F;
}
}
cout << ans;
return 0;
}


## q4x3's solution

/**
* 模拟
* 上坡下坡效果相同（因为有返程）
**/
#include <iostream>
using namespace std;

int main() {
int M, T, U, F, D;
int cnt = 0, tot = 0;
cin >> M >> T >> U >> F >> D;
char tmp;
for(int i = 0;i < T;++ i) {
cin >> tmp;
if(tmp == 'f') {
tot += F * 2;
} else {
tot += (U + D);
}
if(tot > M) break;
else ++ cnt;
}
cout << cnt <<endl;
return 0;
}


## skyzh's solution

#include <iostream>
#include <cstdio>
using namespace std;

char rd[100002];
int main() {
int M, T, U, F, D;
scanf("%d%d%d%d%d\n", &M, &T, &U, &F, &D);
for (int i = 0; i < T; i++) {
scanf("%c\n", &rd[i]);
}
int T_ALL = 0;
for (int i = 0; i < T; i++) {
if (rd[i] == 'u' || rd[i] == 'd') T_ALL += U + D;
if (rd[i] == 'f') T_ALL += F * 2;
if (T_ALL > M) {
cout << i << endl;
return 0;
}
}
cout << T << endl;
return 0;
}


## victrid's solution

#include <iostream>

using namespace std;

int main() {
int M, T, U, F, D;
cin >> M >> T >> U >> F >> D;

char c;
int tf = 0, udt = U + D, fft = F + F;
for (int i = 0; i < T; i++) {
cin >> c;
if (c != 'f')
tf += udt;
else
tf += fft;
if (tf > M) {
cout << i;
break;
}
}
return 0;
}


## yyong119's solution

#include <iostream>
long m,u,f,d,t,i,n;
char si[100001];
int main(){
using namespace std;
cin>>m>>t>>u>>f>>d;
for (i=1; i<=t; i++) cin>>si[i];
while(m>=0){
n++;
if ((si[n]=='u')||(si[n]=='d')) m=m-u-d;
else if(si[n]=='f') m=m-f-f;
}
cout<<n-1;
return 0;
}