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个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ... 
随机推荐
- 【学习笔记】后端中的MVC和前端MVVM的关系
- Bloom Filter概念和原理【转】
			Bloom Filter概念和原理 Bloom Filter是一种空间效率很高的随机数据结构,它利用位数组很简洁地表示一个集合,并能判断一个元素是否属于这个集合.Bloom Filter的这种高效是有 ... 
- 洛谷 P3038 [USACO11DEC]牧草种植Grass Planting
			题目描述 Farmer John has N barren pastures (2 <= N <= 100,000) connected by N-1 bidirectional road ... 
- 1-2 编程基础 GDB程序调试
			简介 GDB是GNU发布的一款功能强大的程序调试工具.GDB主要完成下面三个方面的功能: 1.启动被调试程序 2.让被调试的程序在指定的位置停住. 3.当程序被停住时,可以检查程序状态(如变量值). ... 
- 【整理】用JSON-server模拟REST API
			用JSON-server模拟REST API https://www.cnblogs.com/ys-wuhan/p/6387791.html 
- ES6对象和数组解构
			解构可以避免在对象赋值时再生成多余的中间变量: function foo() { return [1,2,3]; } let arr = foo(); // [1,2,3] let [a, b, c] ... 
- 跑RFCN
			按照这个来http://blog.csdn.net/sinat_30071459/article/details/53202977 
- web中的$多种意思
			$符号在php中是表示变量的特征字符, 在js中它也有很多作用, 一般我们用来命名一个函数名称,获取id的1.首先可以用来表示变量, 比如变量 var s='asdsd'或var $s='asdasd ... 
- 简单DP内容
			1. 最长上升子序列 [题目描述] 给定N个数,求这N个数的最长上升子序列的长度. [样例输入] 7 2 5 3 4 1 7 6 [样例输出] 4 第一种解法:时间复杂度O(n^2), 状态设计:DP ... 
- [JOYOI] 1071 LCIS
			拖了好久的LCIS f[i][j]表示a串前i个,b串以b[j]结尾的LCIS长度. 转移时考虑a[i]和b[j]是否相等,如果不等: 那么既然是以j结尾,说明a串前i-1位有一个字符和b匹配了,所以 ... 
