A. Grandma Laura and Apples

题目连接:

http://www.codeforces.com/contest/632/problem/A

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

2 10

half

halfplus

Sample Output

15

Hint

题意

有n个顾客买苹果,每个苹果p元

half就是这个顾客买了一半的苹果

halfplus就是这个顾客买了一半苹果,最后还送了他半个苹果

最后恰好卖完所有苹果

问你赚了多少钱

题解:

倒着推就好了

当成模拟题做就行了

代码

#include<bits/stdc++.h>
using namespace std; long long ans = 0;
string s[45];
int main()
{
int n,p;scanf("%d%d",&n,&p);
for(int i=0;i<n;i++)
cin>>s[i];
long long now = 0;
for(int i=n-1;i>=0;i--)
{
if(s[i]=="half")
{
ans+=now*p;
now=now*2;
}
else
{
ans+=p/2+now*p;
now=now*2+1;
}
}
cout<<ans<<endl;
}

Educational Codeforces Round 9 A. Grandma Laura and Apples 水题的更多相关文章

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

    题意: 外祖母要卖苹果,(有很多但不知道数量),最终所有苹果都卖光了! 有n个人买苹果,如果那个人是half,他就买所有苹果的一半,如果那个人是halfplus,则他买当前苹果数量的一半,Laura还 ...

  2. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  3. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  4. Codeforces Round #115 B. Plane of Tanks: Pro 水题

    B. Plane of Tanks: Pro Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/17 ...

  5. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  6. Educational Codeforces Round 22 E. Army Creation(分块好题)

    E. Army Creation time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  7. Educational Codeforces Round 59 (Rated for Div. 2) (前四题)

    A. Digits Sequence Dividing(英文速读) 练习英语速读的题,我还上来昏迷一次....只要长度大于2那么一定可以等于2那么前面大于后面就行其他no 大于2的时候分成前面1个剩下 ...

  8. Educational Codeforces Round 6 A. Professor GukiZ's Robot 水

    A. Professor GukiZ's Robot   Professor GukiZ makes a new robot. The robot are in the point with coor ...

  9. Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题

    A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...

随机推荐

  1. Python阶段复习 - part 4 - 用户登录程序

    简易版: #!/usr/bin/env python # _*_ coding:UTF-8 _*_ # __auth__:Dahlhin import sys userinfo = r'userinf ...

  2. 细数雷军系成员,27家公司3家IPO

    自 2004 年至今,作为天使投资人和顺为基金创始合伙人,雷军共投了移动互联网.电子商务.互联网社区等领域内的 27 家创业公司,其中欢聚时代.猎豹移动.迅雷三家公司成功上市.小米科技虽然还未 IPO ...

  3. 函数导出在kvm_intel.ko,kvm.ko不共享

    KVM一共包含了三个内核模块,kvm_intel.ko,kvm_amd.ko,kvm.ko.其中两个重要文件x86.c和vmx.c在编译后分别会生成kvm_intel.ko和kvm.ko两个内核模块, ...

  4. Linux实际用户(组)ID,有效用户(组)ID,设置用户(组)ID

    实际用户(组)ID: 标识用户是谁,这两个字段在登录时取自口令文件中的登录项. 有效用户(组)ID: 决定了对文件的访问权限,通常有效用户(组)ID等于实际用户(组)ID,谁运行有效ID就等于谁的实际 ...

  5. pillow模块的学习

    https://github.com/wangbinyq/pillow_example http://pillow.readthedocs.org/en/latest/handbook/tutoria ...

  6. monkey测试===关于monkey测试的介绍

    https://www.cnblogs.com/lauren1003/p/6193277.html

  7. 算法题之找出数组里第K大的数

    问题:找出一个数组里面前K个最大数. 解法一(直接解法): 对数组用快速排序,然后直接挑出第k大的数.这种方法的时间复杂度是O(Nlog(N)).N为原数组长度. 这个解法含有很多冗余,因为把整个数组 ...

  8. git清除用户名密码

    问题: remote: HTTP Basic: Access deniedfatal: Authentication failed for 'http://******** 解决方案: git con ...

  9. Flask 的系统学习

    详细看地址: http://www.cnblogs.com/wupeiqi/articles/7552008.html 一. 说明 Flask是一个基于Python开发并且依赖jinja2模板和Wer ...

  10. AC日记——NOI2016区间 bzoj 4653

    4653 思路: 线段树,指针滑动: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1000005 #def ...