CodeForces 632A
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
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
15
3 10
halfplus
halfplus
halfplus
55
真不明白我们学长,拉题都拉到cf
上了,结果他们拉的题自己也做不出几道,,反倒是学弟学妹们踊跃的A了,难道是他们已经A了,,,,,
cf上的题,,众所周知,全是密密麻麻的英文,,我去。。
呐,这题看了半天知道了题意,可死活不造输出是怎么得到的,看着榜上那么多人A了,心灰意冷,,后来比完赛回寝室同学说如果是奇数那么卖一半,送半个,比如7个,卖3.5个,送0.5个,所以需要付35块钱,拿走了四个,,瞬间感觉无语了,,,读了好多遍题推算出最后一定是一个苹果,而且字符串最后一定有plus,,,
所以可以逆推,第二天看他们的提交AC答案,方法很多,不过思路清晰快速基本就没什么问题了。。。。。‘
贴上简洁易懂代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
int n,p,i;
double x;
long long sum;
char a[41][10];
while(~scanf("%d%d",&n,&p))
{
x=1.0;
sum=p/2.0;
for(i=0;i<n;i++)
scanf("%s",a[i]);
for(i=n-2;i>=0;i--)//<span style="font-size: 12.6315793991089px;">字符串最后一定是plus,不用从n-1开始逆推;</span>
{
if(strlen(a[i])>4)
{
x=x*2.0+1.0;
sum+=p*x/2.0;
}
else
{
x=x*2.0;
sum+=p*x/2.0;
}
}
printf("%I64d\n",sum);
}
return 0;
}
CodeForces 632A的更多相关文章
- codeforces 632A A. Grandma Laura and Apples(暴力)
A. Grandma Laura and Apples time limit per test 1 second memory limit per test 256 megabytes input s ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- 486 Predict the Winner 预测赢家
给定一个表示分数的非负整数数组. 玩家1从数组任意一端拿取一个分数,随后玩家2继续从剩余数组任意一端拿取分数,然后玩家1拿,…….每次一个玩家只能拿取一个分数,分数被拿取之后不再可取.直到没有剩余分数 ...
- 166 Fraction to Recurring Decimal 分数到小数
给定两个整数,分别表示分数的分子和分母,返回字符串格式的小数.如果小数部分为循环小数,则将重复部分括在括号内.例如, 给出 分子 = 1, 分母 = 2,返回 "0.5". ...
- (021)VMWare副虚拟磁盘和子虚拟磁盘id不匹配
问题:因为某种原因,修改了VM虚拟机的父磁盘内容,导致开机时出现如下错误: 父虚拟磁盘在子虚拟磁盘创建之后被修改过.父虚拟磁盘的内容 ID 与子虚拟磁盘中对应的父内容 ID 不匹配打不开磁盘“***. ...
- RHEL 6.5----haproxy实现负载均衡
主机名 IP master 192.168.30.130 node-1 192.168.30.131 node-2 192.168.30.132 在master上安装 [root@master ~]# ...
- C#将excel数据按照需求导入Sql server遇到的问题(参考而已)
1.千万不要使用永中表格(WPS没用过,这里只是个人观点,不是说永中表格的) 我在公司得到的任务是将excel数据按照需求导入数据库总共主表大概3张,所以有点复杂(列子用的简单表,公司东西还是不要放出 ...
- k-window的关闭与打开设置
// 打开弹框窗口 public showKwinDow() { const that = this as any; // 设置窗口居中 that.$refs['setAddEdit'].widget ...
- 【译】OpenStack Heat基础介绍
原文:http://blog.scottlowe.org/2014/05/01/an-introduction-to-openstack-heat/ 本文将简要地介绍OpenStack Heat. H ...
- like SQL注入与防止 (bin2hex unhex)
普通的列表模糊查询,可能会被sql注入利用,造成数据泄漏,严重的甚至导致删表删库! 程序中sql语句拼装: $sql = 'student_name like '"%'.$name.'%&q ...
- c# sqlserver连接字符串
odbc: string cnnstring = @"Driver={SQL Server Native Client 11.0};Initial Catalog = sxquadb;ser ...
- pocket API学习笔记
最近安装了pocket离线阅读软件. 为了收藏需要的URL,每次都要打开浏览器.然后按google工具条上的pocket+. 网页多的时候,这个过程就非常缓慢. 根据pocket网站的API介绍,我可 ...