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 10
half
halfplus
output
15
input
3 10
halfplus
halfplus
halfplus
output
55
Note 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;
}

codeforces 632A A. Grandma Laura and Apples(暴力)的更多相关文章

  1. Educational Codeforces Round 9 A. Grandma Laura and Apples 水题

    A. Grandma Laura and Apples 题目连接: http://www.codeforces.com/contest/632/problem/A Description Grandm ...

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

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

  3. CodeForces 632C Grandma Laura and Apples (模拟)

    题意:有n个人买苹果,当苹果剩余偶数时买走一半,当苹果剩余奇数时,先买走一半,再用半价买走一个苹果,最终苹果恰好卖完.农民收入为多少. 析:反向模拟. 代码如下: #pragma comment(li ...

  4. [CF632A]Grandma Laura and Apples

    题目大意:有$n$个顾客买苹果,每个买一半的苹果,有时会送半个苹果.最后卖光了,问卖了多少钱 题解:倒退过来,可以把半个苹果当做一份来算,这样不会有小数 卡点:无 C++ Code: #include ...

  5. 【Henu ACM Round #12 A】 Grandma Laura and Apples

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 知道题意之后就是一个模拟的过程了. 用int now记录当前苹果的个数.bool flag记录是否有小数(即半个苹果) (这样处理为 ...

  6. CodeForces 632A

    A - Grandma Laura and Apples Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  7. Codeforces Gym 100803F There is No Alternative 暴力Kruskal

    There is No Alternative 题目连接: http://codeforces.com/gym/100803/attachments Description ICPC (Isles o ...

  8. Codeforces Beta Round #13 E. Holes 分块暴力

    E. Holes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/13/problem/E Des ...

  9. Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力

    B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...

随机推荐

  1. 利用asset存储mesh

    做mesh导出的时候遇到了这个问题. 最后解决: 存储mesh数据:AssetDatabase.CreateAsset(meshfilter.mesh, "Assets/" + & ...

  2. jquery插件2

    1.很全,好用的jquery插件库:http://www.jq22.com/ 2.素材:http://www.sucaijiayuan.com/ 3.不错:http://www.helloweba.c ...

  3. window下php5安装redis扩展 设置自启动服务

    最近想在5.6版本的开发环境装一下redis的扩展,结果找了半天都是失效链接,特此做下备份 5.3-5.6 https://pecl.php.net/package/redis/2.2.7/windo ...

  4. python在windows下安装paramiko模块和安装pycrypto模块(3步搞定)(转)

    Python中使用SSH需要用到OpenSSH,而OpenSSH依赖于paramiko模块,而paramiko模块又依赖于pycrypto模块,因此要在Python中使用SSH,我们需要先安装pycr ...

  5. GUN C中的错误报告

    在C语言中,很多库函数在调用失败时都会返回特定的值.比如返回-1,空指针,EOF等.但是这些值仅仅表示的调用失败,并未给出详细的错误信息.如果想查看详细的错误内容,就要去查看errno的错误代码,er ...

  6. 论JavaWeb前后端分离放弃jsp

    1.静态资源使用Nginx反向代理Tomcat,Tomcat挂了网站仍可访问.2.静态与后端服务器分离,提升性能.3.大并发情况下,可同时扩展前后端服务器.4.接口可复用至App相关服务.5.网站热部 ...

  7. 记录-MySQL中的事件调度Event Scheduler

    下面是自己的实例 /*查询event是否开启(查询结果Off为关闭 On为开启)*/show variables like '%sche%'; /*开启/关闭命令(1开启--0关闭)*/set glo ...

  8. 6.2.1-FactoryBeanRegistrySupport(未全)

    FactoryBeanRegistrySupport 的关系图: 添加工厂方式创建类FactoryBean的支持

  9. 如何将gedit变成c++编译器

    本蒟蒻的第一篇文章,分享一下神佬教我的好东西 ——将Ubuntu 16.04上gedit变为编译器! 1° 新建文档.然后点击编辑,打开首选项. 2° 勾选外部工具,然后退出.打开工具,选择Manag ...

  10. [note]可持久化Trie

    可持久化Trie 参考可持久化线段树的思想,修改的时候先直接复制,再对需要修改的点新建节点 可持久化Trie也是同样的做法,假设现在需要在原本Trie的基础上插入一个字符串 先把上个Trie的对应节点 ...