Educational Codeforces Round 9 A. Grandma Laura and Apples 水题
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 水题的更多相关文章
- Educational Codeforces Round 9 -- A - Grandma Laura and Apples
题意: 外祖母要卖苹果,(有很多但不知道数量),最终所有苹果都卖光了! 有n个人买苹果,如果那个人是half,他就买所有苹果的一半,如果那个人是halfplus,则他买当前苹果数量的一半,Laura还 ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- 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 ...
- 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 ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...
- 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 ...
- Educational Codeforces Round 59 (Rated for Div. 2) (前四题)
A. Digits Sequence Dividing(英文速读) 练习英语速读的题,我还上来昏迷一次....只要长度大于2那么一定可以等于2那么前面大于后面就行其他no 大于2的时候分成前面1个剩下 ...
- 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 ...
- 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 ...
随机推荐
- vue基本介绍
https://cn.vuejs.org/v2/guide/ Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架.与其它大型框架不同的是,Vue 被设计为可以自底向上 ...
- nfs 文件共享 服务
需要rpc服务: [root@xujiaxuan ftp]# service rpcbind start[root@xujiaxuan ftp]# chkconfig rpcbind on 设置开机自 ...
- 2.Python3标准库--文本
(一)string:文本常量和模板 1.函数 import string ''' string模块在最早的Python版本中就已经有了.以前这个模块中提供的很多函数已经移植到str对象中,不过这个模块 ...
- EXT入门学习
今天,对EXT做了一下初步的了解,了解了一些基本用的函数.窗体对象.表单.文本域.按钮,一些基本的函数我列了出来,写了个登陆的demo,是根据别人的例子模仿出来的,见谅哈. 基本函数 Ext.onRe ...
- WdatePicker做出onchange效果
WdatePicker({onpicking: function (dp) {if (dp.cal.getDateStr() != dp.cal.getNewDateStr()) { Func(dp. ...
- java - 线程1打印1-10,当线程打印到5后,线程2打印“hello”,然后线程1继续打印
public class T { private static int a =1;//1代表线程1 2线程2 public static void main(String[] args) { fina ...
- Freemarker的页面和JS遍历后台传入的Map
后端传到前端的Map Freemarker页面遍历Map: JS遍历Map:
- 《java并发编程实战》读书笔记3--对象的组合
希望将一些现有的线程安全组件组合为更大规模的组件或程序 设计线程安全的类 如果对象中所有的域是基本类型变量,那么这些域将构成对象的全部状态.例如,LinkedList的状态就包括该链表中所有节点对象的 ...
- Linked List Cycle I&&II——快慢指针(II还没有完全理解)
Linked List Cycle I Given a linked list, determine if it has a cycle in it. Follow up: Can you solve ...
- nginx反向代理二级页面
当公司只存在一个公网地址时候,需要影射多个域名,并且域名下面要配置二级目录的时候 可以参照如下配置 upstream h5_game { server 10.0.100.153:80; } serve ...