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中的binascii模块

    binascii模块拿来干嘛的? 答:进制转换xxoo #!/usr/bin/env python # encoding:utf-8 # by i3ekr import binascii s = &q ...

  2. Python模块学习 - click

    Click模块 click模块是Flask的作者开发的一个第三方模块,用于快速创建命令行.它的作用与Python标准库的argparse相同,但是,使用起来更简单. click是一个第三方库,因此使用 ...

  3. Which cryptsetup

    Which cryptsetup Rpm –qf ‘which cryptsetup’ 安装加密工具: 设置加密分区 Crptsetup luksFormat Echo –n “xuegod123”  ...

  4. 64_g2

    gettext-libs-0.19.8.1-9.fc26.x86_64.rpm 15-Mar-2017 14:15 305038 gf2x-1.1-9.fc26.i686.rpm 11-Feb-201 ...

  5. zip函数的应用

    #!/usr/bin/env python # encoding: utf-8 from itertools import zip_longest # ➍ # zip并行从输入的各个可迭代对象中获取元 ...

  6. Lodash使用示例(比较全)

    <html> <head> <meta name="viewport" content="width=device-width" ...

  7. java 多线程剖析

    问题的缘由源自于一道简单的面试题:题目要求如下: 建立三个线程,A线程打印10次A,B线程打印10次B,C线程打印10次C,要求线程同时运行,交替打印10次ABC. 解决问题前我们前补充一些基本知识: ...

  8. iOS---弹出提示对话框

    一.就一个选项的对话框 代码块 #pragma mark - 封装弹出对话框方法 // 提示错误信息 - (void)showError:(NSString *)errorMsg { // 1.弹框提 ...

  9. HDU 2829 Lawrence(斜率优化DP O(n^2))

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2829 题目大意:有一段铁路有n个站,每个站可以往其他站运送粮草,现在要炸掉m条路使得粮草补给最小,粮草 ...

  10. textarea在浏览器中固定大小

    HTML 标签 textarea 在大部分浏览器中只要指定行(rows)和列(cols)属性,就可以规定 textarea 的尺寸,大小就不会改变,不过更好的办法是使用 CSS 的 height 和 ...