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

时间:2023-01-30 11:14:56

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 &num;367 &lpar;Div&period; 2&rpar; A&period; Beru-taxi (水题)

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

  3. Codeforces Round &num;334 &lpar;Div&period; 2&rpar; A&period; Uncowed Forces 水题

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

  4. Codeforces Round &num;115 B&period; Plane of Tanks&colon; Pro 水题

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

  5. Codeforces Round &num;353 &lpar;Div&period; 2&rpar; A&period; Infinite Sequence 水题

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

  6. Educational Codeforces Round 22 E&period; 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 &lpar;Rated for Div&period; 2&rpar; (前四题)

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

  8. Educational Codeforces Round 6 A&period; Professor GukiZ&&num;39&semi;s Robot 水

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

  9. Codeforces Round &num;327 &lpar;Div&period; 2&rpar; A&period; Wizards&&num;39&semi; Duel 水题

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

随机推荐

  1. WPF学习之路(五) 实例:写字板

    写字板实例一 MainWindow.xaml <Window x:Class="Wordpad01.MainWindow" xmlns="http://schema ...

  2. &lbrack;ActionScript 3&period;0&rsqb; AS3&period;0 本机鼠标指针

    Flash Player 10.2添加了内置的本机鼠标指针(native mouse cursor)支持,虽然在之前的版本里我们可以侦听MouseEvent事件来模拟鼠标指针,但是在有了原生的本机鼠标 ...

  3. 最短路知识点总结(Dijkstra,Floyd,SPFA,Bellman-Ford)

    Dijkstra算法: 解决的问题: 带权重的有向图上单源最短路径问题.且权重都为非负值.如果采用的实现方法合适,Dijkstra运行时间要低于Bellman-Ford算法. 思路: 如果存在一条从i ...

  4. 一点公益二码公益开发模式系统源码App

    写这篇文章,是因为最近看到的一个著名的开源项目在内部使用时的各种问题,不得不说,很多的开源的东西思想是不错的,但离真正工程化都有不小的距离,所以没什么商业公司采用的开源产品如果要引入的话一定要慎重,通 ...

  5. java&plus;tomcat&plus;Eclipse&plus;mysql配置

    Java下载及配置: 1. 下载:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html ...

  6. 在ubuntu16&period;04中一键创建LAMP环境

    步骤 1 执行命令apt-get update. 步骤 2 执行命令apt-get install lamp-server^. 步骤 3 在安装过程中会跳出Mysql数据库root用户密码设置窗口,按 ...

  7. 关于ios手机游览器针对overflow:hidden设置无效的解决办法

    Ordinarily, overflow: hidden; on the body tag is sufficient to prevent scrolling a web page, if for ...

  8. 利用CSS3实现鼠标悬停在图片上图片缓慢缩放的两种方法

    1.改变background-size属性 将图片作为某个html元素的背景图片,用transition属性改变图片的大小. .container{ background-size: 100% 100 ...

  9. vSCode打开文件老覆盖原窗口

    https://segmentfault.com/q/1010000006131199?_ea=1023522 设置中搜preview,改为false

  10. Mysql开启远程服务

    开启远程服务: 登录mysql: //赋予root用户所有权限,远程登录密码是123456 grant all privileges on *.* to '; flush privileges; 设置 ...