CodeForces 632A
2016-03-23 09:20
295 查看
A - Grandma Laura and Apples
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice CodeForces
632A
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
Input
Output
Input
Output
真不明白我们学长,拉题都拉到cf
上了,结果他们拉的题自己也做不出几道,,反倒是学弟学妹们踊跃的A了,难道是他们已经A了,,,,,
cf上的题,,众所周知,全是密密麻麻的英文,,我去。。
呐,这题看了半天知道了题意,可死活不造输出是怎么得到的,看着榜上那么多人A了,心灰意冷,,后来比完赛回寝室同学说如果是奇数那么卖一半,送半个,比如7个,卖3.5个,送0.5个,所以需要付35块钱,拿走了四个,,瞬间感觉无语了,,,读了好多遍题推算出最后一定是一个苹果,而且字符串最后一定有plus,,,
所以可以逆推,第二天看他们的提交AC答案,方法很多,不过思路清晰快速基本就没什么问题了。。。。。‘
贴上简洁易懂代码:
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice CodeForces
632A
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
Input
2 10 half halfplus
Output
15
Input
3 10 halfplus halfplus halfplus
Output
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; }
相关文章推荐
- DataGridView初始化——添加列、添加行号、连接数据库、单击单元格在文本框中显示
- CoordinatorLayout与滚动的处理
- 关于dbms_output包的使用
- 输入文本框 右边有自带的删除按钮
- 使用Jmeter进行http接口测试
- PAT 1040
- sql 去除html标签函数
- PAT 1040
- 开发者了解---微信公众号(服务号、订阅号、企业号)的区别
- Spring AOP原理及拦截器
- android-2016-常见面试题总结(一)
- UIWebView的一些用法总结
- hessian学习_有例子
- 【Latex】如何在Latex中插入伪代码 —— clrscode3e
- 第三周作业(三)
- is interest important?
- HTTP协议和HTTPS协议初探
- java中的栈和堆
- HTML网页版2048小游戏
- orcal数据和表闪回命令及执行含有特殊符号