CodeForces 632A

来源:互联网 发布:mysql 禁用主键 编辑:程序博客网 时间:2024/05/02 20:27

A - Grandma Laura and Apples
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 632A

Description

Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.

She precisely remembers she had n buyers and each of them bought exactly half of the apples she had at the moment of the purchase and also she gave a half of an apple to some of them as a gift (if the number of apples at the moment of purchase was odd), until she sold all the apples she had.

So each buyer took some integral positive number of apples, but maybe he didn't pay for a half of an apple (if the number of apples at the moment of the purchase was odd).

For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is p (the number p is even).

Print the total money grandma should have at the end of the day to check if some buyers cheated her.

Input

The first line contains two integers n and p (1 ≤ n ≤ 40, 2 ≤ p ≤ 1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number p is even.

The next n lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of the apples and with the string halfplus if grandma also gave him a half of an apple as a gift.

It is guaranteed that grandma has at least one apple at the start of the day and she has no apples at the end of the day.

Output

Print the only integer a — the total money grandma should have at the end of the day.

Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Sample Input

Input
2 10halfhalfplus
Output
15
Input
3 10halfplushalfplushalfplus
Output
55

          真不明白我们学长,拉题都拉到cf上了,结果他们拉的题自己也做不出几道,,反倒是学弟学妹们踊跃的A了,难道是他们已经A了,,,,,

             cf上的题,,众所周知,全是密密麻麻的英文,,我去。。

     呐,这题看了半天知道了题意,可死活不造输出是怎么得到的,看着榜上那么多人A了,心灰意冷,,后来比完赛回寝室同学说如果是奇数那么卖一半,送半个,比如7个,卖3.5个,送0.5个,所以需要付35块钱,拿走了四个,,瞬间感觉无语了,,,读了好多遍题推算出最后一定是一个苹果,而且字符串最后一定有plus,,,

所以可以逆推,第二天看他们的提交AC答案,方法很多,不过思路清晰快速基本就没什么问题了。。。。。‘

           贴上简洁易懂代码:

                                 

#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>using namespace std;int main(){    int n,p,i;    double x;    long long sum;    char a[41][10];    while(~scanf("%d%d",&n,&p))    {        x=1.0;        sum=p/2.0;        for(i=0;i<n;i++)            scanf("%s",a[i]);            for(i=n-2;i>=0;i--)//<span style="font-size: 12.6315793991089px;">字符串最后一定是plus,不用从n-1开始逆推;</span>            {                if(strlen(a[i])>4)                {                    x=x*2.0+1.0;                    sum+=p*x/2.0;                }                else                {                    x=x*2.0;                    sum+=p*x/2.0;                }            }           printf("%I64d\n",sum);    }    return 0;}


0 0
原创粉丝点击