codeforces 632A A. Grandma Laura and Apples

A. Grandma Laura and Apples

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples

input

2 10halfhalfplus

output

15

input

3 10halfplushalfplushalfplus

output

55Note

In the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer.

题意:half是买一半的苹果,halfplus是买一半的苹果并送半个,问最后得到多少钱;

思路:全都*2,从最后一个开始算到第一个;

AC代码:

#include <bits/stdc++.h>
using namespace std;
string str[1004];
long long n,p;
int main()
{

    cin>>n>>p;
    for(int i=0;i<n;i++)
    {
        cin>>str[i];
    }
    long long sum=0,ans=0;
    for(int i=n-1;i>=0;i--)
    {
        if(str[i]=="halfplus")
        {
            sum+=1;
            ans+=sum*p;
            sum*=2;

        }
        else
        {
            ans+=sum*p;
            sum*=2;
        }
    }
    cout<<ans/2<<endl;
    return 0;
}
时间: 2024-10-27 06:54:32

codeforces 632A A. Grandma Laura and Apples的相关文章

[2016-03-26][codeforces][632][A][Grandma Laura and Apples]

时间:2016-03-25 23:50:29 星期五 题目编号:[2016-03-26][codeforces][632][A][Grandma Laura and Apples] 题目大意:有n的客人,每个客人都来买一半的苹果,如果苹果为奇数,就把多出来的半个苹果送给客人,已知买个客人是否收到更多苹果,问总共应该收到多少元 分析: 最后剩下一个苹果的时候,客人只买半个苹果,送半个苹果,所以最后一个一定是plus, 直接计算所有苹果的数目,和赠送的苹果数目,求最后总值 #include <cst

Educational Codeforces Round 9 -- A - Grandma Laura and Apples

题意: 外祖母要卖苹果,(有很多但不知道数量),最终所有苹果都卖光了! 有n个人买苹果,如果那个人是half,他就买所有苹果的一半,如果那个人是halfplus,则他买当前苹果数量的一半,Laura还会送半个苹果!问最多能赚多少钱? 思路: 会后一个人一定是halfplus,否则苹果卖不完,所以最后一个人买的时候已经只剩一个.然后从后往前推. 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #

CodeForces 632C Grandma Laura and Apples (模拟)

题意:有n个人买苹果,当苹果剩余偶数时买走一半,当苹果剩余奇数时,先买走一半,再用半价买走一个苹果,最终苹果恰好卖完.农民收入为多少. 析:反向模拟. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include &l

CF632A Grandma Laura and Apples

#include<bits/stdc++.h> using namespace std; long long n,p,ans=0,total=0,apple=0; int main() { string a[100000]; cin>>n>>p; p=p>>1; for(int i=1;i<=n;i++) { cin>>a[i]; } for(int i=n;i>=1;i--) { total=total*2; if(a[i]==&q

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

CodeForces 23C Oranges and Apples 抽屉原理

题目链接:点击打开链接 #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <map> #include <set> #include <math.h> using namespace std; #define inf 10000000 #define l

CodeForces 449C Jzzhu and Apples 数学+素数

这道题目晚上本来就花了很多把都××了,着实觉得自己思路没错啊,回顾一下思路,给你n个数,分成两两组合一对,分成最多组如何分,但是组合的两个数 不能互素,所以呢 偶数肯定是好的了,所以先放着,先把素数给搞定,10^5所以枚举所有包含该素数因子的数,如果刚好分组则最好,不然的话其中有偶数的踢掉一个给下面的偶数处理部分,最后再处理偶数的部分,这样肯定满足组数最多,完全没有问题,后来方法确实是没问题啊,只是代码有问题,我靠!真是脑残!,今天看到一位大牛的想法,我跟他是一样的,只是代码写搓了,后来改了又改

Codeforces 449C Jzzhu and Apples(构造)

题目链接:Codeforces 449C Jzzhu and Apples 题目大意:Jzzhu从苹果树上获得n个苹果,标号从1~n,现在要将他们以两个为一组卖给商家,要求一组中的两个苹果的编号最大公约数大于1,分的组数尽量多. 解题思路:枚举公约数d,只枚举素数,因为合数的可以在更小的素数被枚举.将所有没用过并且编号为d的倍数的苹果拿出来,两两组队,如果个数为奇数,那么就将2d留出来.因为d>2,所以第2个肯定是2d.并且2d是2的倍数. #include <cstdio> #incl

Codeforces Round #325 (Div. 2) E. Alice, Bob, Oranges and Apples

E. Alice, Bob, Oranges and Apples Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining frui