codeforces 632A A. Grandma Laura and Apples(暴力)
1 second
256 megabytes
standard input
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.
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.
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.
2 10
half
halfplus
15
3 10
halfplus
halfplus
halfplus
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(暴力)的更多相关文章
- Educational Codeforces Round 9 A. Grandma Laura and Apples 水题
A. Grandma Laura and Apples 题目连接: http://www.codeforces.com/contest/632/problem/A Description Grandm ...
- Educational Codeforces Round 9 -- A - Grandma Laura and Apples
题意: 外祖母要卖苹果,(有很多但不知道数量),最终所有苹果都卖光了! 有n个人买苹果,如果那个人是half,他就买所有苹果的一半,如果那个人是halfplus,则他买当前苹果数量的一半,Laura还 ...
- CodeForces 632C Grandma Laura and Apples (模拟)
题意:有n个人买苹果,当苹果剩余偶数时买走一半,当苹果剩余奇数时,先买走一半,再用半价买走一个苹果,最终苹果恰好卖完.农民收入为多少. 析:反向模拟. 代码如下: #pragma comment(li ...
- [CF632A]Grandma Laura and Apples
题目大意:有$n$个顾客买苹果,每个买一半的苹果,有时会送半个苹果.最后卖光了,问卖了多少钱 题解:倒退过来,可以把半个苹果当做一份来算,这样不会有小数 卡点:无 C++ Code: #include ...
- 【Henu ACM Round #12 A】 Grandma Laura and Apples
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 知道题意之后就是一个模拟的过程了. 用int now记录当前苹果的个数.bool flag记录是否有小数(即半个苹果) (这样处理为 ...
- CodeForces 632A
A - Grandma Laura and Apples Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- Codeforces Gym 100803F There is No Alternative 暴力Kruskal
There is No Alternative 题目连接: http://codeforces.com/gym/100803/attachments Description ICPC (Isles o ...
- Codeforces Beta Round #13 E. Holes 分块暴力
E. Holes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/13/problem/E Des ...
- Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力
B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...
随机推荐
- chattr
chattr 功能:设置文件隐藏属性常用参数:+ 增加某个特殊权限,其他原本存在的参数不动- 删除某个特殊权限,其他原本存在的参数不动= 设置一定,且仅有后面接的参数 i 文件 ...
- 创建有提示的ui组件
using UnityEditor; using UnityEngine; using System.Collections; using Edelweiss.CloudSystem; namespa ...
- Unity中surfaceShader的处理机制和finalColor
http://blog.csdn.net/swj524152416/article/details/52945375
- BZOJ 1602 [Usaco2008 Oct]牧场行走 dfs
题意:id=1602">链接 方法:深搜暴力 解析: 这题刚看完还有点意思,没看范围前想了想树形DP,只是随便画个图看出来是没法DP的,所以去看范围. woc我没看错范围?果断n^2暴 ...
- python 基础 9.6 设计表结构
一. 设计表结构 在操作设计数据库之前,我们先要设计数据库表结构,我们就来分析分析经典的学生,课程,成绩,老师这几者他们之间的关系,我们先来分析各个主体他们直接有什么属性,并确定表结构,在实际开 ...
- mysql如何监测是否命中索引?
使用执行计划. 什么是执行计划? EXPLAIN SELECT …… 变体: 1. EXPLAIN EXTENDED SELECT …… 将执行计划“反编译”成SELECT语句,运行SHOW WARN ...
- 【BZOJ2460】[BeiJing2011]元素 贪心+高斯消元求线性基
[BZOJ2460][BeiJing2011]元素 Description 相传,在远古时期,位于西方大陆的 Magic Land 上,人们已经掌握了用魔法矿石炼制法杖的技术.那时人们就认识到,一个法 ...
- docker笔记一
docker概念介绍: docker 是一个装在linux上的普通的软件.利用docker的命令,可以创建一个带有linux操作系统的镜像文件,docker命令运行这个带的linux操作系的镜像文件, ...
- <%%>与<scriptrunat=server>,<%=%>与<%#%>的区别(转)
这些东西都是asp.net前台页面与后台代码交互过程中经常使用的,它们之间有的非常相似,又有一些不同.对比学习下,看看他们之间的联系与区别. 首先看<%%>与<scriptrunat ...
- Bytecode Visualizer 一个好用的class字节码查看工具
http://www.drgarbage.com/howto/install/ eclipse插件,效果如下: