Educational Codeforces Round 9 -- A

题意:

外祖母要卖苹果,(有很多但不知道数量),最终所有苹果都卖光了!
有n个人买苹果,如果那个人是half,他就买所有苹果的一半,如果那个人是halfplus,则他买当前苹果数量的一半,Laura还会送半个苹果!问最多能赚多少钱?
思路:
会后一个人一定是halfplus,否则苹果卖不完,所以最后一个人买的时候已经只剩一个。然后从后往前推。
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<iostream>
 5 #include<cstdlib>
 6 #include<string>
 7 #include<cmath>
 8 #include<vector>
 9 using namespace std;
10 const int maxn=1e5+7;
11 const double eps=1e-8;
12 const double pi=acos(-1);
13 #define ll long long
14 int main()
15 {
16     ll n,m;
17     char str[100][100];
18     while(~scanf("%I64d%I64d",&n,&m))
19     {
20         ll num=0;
21         ll ans=0;
22         for(int i=0;i<n;i++)
23             scanf("%s",str[i]);
24         for(int i=n-1;i>=0;i--)
25         {
26             if(!strcmp(str[i],"halfplus"))
27             {
28                 num=(num+0.5)*2;
29                 ans+=num/2.0*m;
30             }
31             else
32             {
33                 num=num*2;
34                 ans+=num/2*m;
35             }
36         }
37         printf("%I64d
",ans);
38     }
39     return 0;
40 }
View Code
原文地址:https://www.cnblogs.com/ITUPC/p/5234735.html