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个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- [已读]编写可维护的javascript
13年4月份出版,作者是大名鼎鼎的Zakas,他的另两本书<javascript高级程序设计>与<高性能javascript>你一定听过或者读过. 这本书重点讲了编码风格和编码 ...
- RHEL 6.5 ----Postfix邮件服务器
主机名 IP 服务 master 192.168.30.130 slave 192.168.30.131 软件包介绍 包名 介绍 postfix-2.6.6-2.2.el6_1.x86 ...
- asp.net 线程批量导入数据,ajax获取执行状态
最近做了一个批量导入功能,长时间运行,没个反馈状态,很容易让人看了心急,产生各种臆想!为了解决心里障碍,写了这么个功能. 通过线程执行导入,并把正在执行的状态存入session,既共享执行状态,通过a ...
- 小程序java解密
<dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcprov-jdk16< ...
- iPhone4 offical AD
iPhone4 is so much more than just a new products.I mean this would have a lot of impact on the way i ...
- WEB前端JS与UI框架
前端Js框架汇总 概述: 有些日子没有正襟危坐写博客了,互联网飞速发展的时代,技术更新迭代的速度也在加快.看着Java.Js.Swift在各领域心花路放,也是煞是羡慕.寻了寻.net的消息,也是振奋人 ...
- 手把手教你免费把网站IP换成1.1.1.1/1.0.0.1
近日,Cloudflare官方发文,与APNIC官方合作打算用IP1.1.1.1推出速度更快.私密性更强的DNS Cloudflare 运行全球规模最大.速度最快的网络之一. APNIC 是一个非营利 ...
- expand - 把 tab 符转换为空格符
总览 (SYNOPSIS) ../src/expand [OPTION]... [FILE]... 描述 (DESCRIPTION) 把 各文件 FILE 中的 tab 符 转换为 空格符, 然后 写 ...
- dirname, basename - 分析路径成员
总览 (SYNOPSIS) #include <libgen.h> char *dirname(char *path); char *basename(char *path); 描述 (D ...
- docker 深入理解之namespace
namespace 名称空间 docker容器主要通过资源隔离来实现的,应该具有的6种资源隔 namespace 的六项隔离 namespace 系统调用参数 隔离的内容 UTS CLONE_NEWU ...