Codeforces 632A Grandma Laura and Apples 【水题】
来源:互联网 发布:网络乌托邦啥意思 编辑:程序博客网 时间:2024/05/16 01:37
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 10halfhalfplus
15
3 10halfplushalfplushalfplus
55
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.
简略题意:有n个人来买苹果,half 表示这个人买苹果时剩余苹果数是偶数且他买走一半,halfplus表示这个人买苹果时剩余苹果数是奇数且他买走一半 并花半价又买走一个。给定每个苹果的单价,问获得的钱。
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <map>#include <string>#include <vector>#include <stack>#define CLR(a, b) memset(a, (b), sizeof(a))using namespace std;typedef long long LL;const int MOD = 1e9+7;const int MAXN = 1e5+10;void add(LL &x, LL y) {x += y; x %= MOD;}char str[50][10];int main(){ int n, p; cin >> n >> p; for(int i = 0; i < n; i++) cin >> str[i]; LL num = 0; for(int i = n-1; i >= 0; i--) { if(str[i][4] == 'p') num = num * 2 + 1LL; else num *= 2; } LL ans = 0; for(int i = 0; i < n; i++) { if(str[i][4] == 'p') { num >>= 1; ans += num * p + p / 2; } else { num >>= 1; ans += num * p; } } cout << ans << endl; return 0;}
- CodeForces 632A-Grandma Laura and Apples
- codeforces-632A-Grandma Laura and Apples
- CodeForces-632A-Grandma Laura and Apples
- codeforces 632A Grandma Laura and Apples
- Codeforces 632A Grandma Laura and Apples 【水题】
- CodeForces 632A Grandma Laura and Apples(水题)
- CodeForces 632 A.Grandma Laura and Apples(水~)
- codeforces 632A Grandma Laura and Apples 模拟
- Educational Codeforces Round 9 A. Grandma Laura and Apples【水题】
- Educational Codeforces Round 9 -- A - Grandma Laura and Apples
- Educational Codeforces Round 9-A. Grandma Laura and Apples(模拟)
- codeforces--623A Grandma Laura and Apples(math)
- CF #632A(A. Grandma Laura and Apples,)数学题
- (Educational Codeforces Round)Grandma Laura and Apples(水题)
- codeforces_632A.Grandma Laura and Apples
- edu round 9 A-Grandma Laura and Apples
- 632A.Gradma Laura and Apples
- codeforces 632aGrandma Laura and Apples(构造)
- Hadoop 2.x高可用配置
- ACM输入输出格式记录
- 针对数据泵导出 (expdp) 和导入 (impdp)工具性能降低问题的检查表 (文档 ID 1549185.1)
- 【GDKOI2016】QT与泰剧Code&Details
- Linux下设置程序自启动
- Codeforces 632A Grandma Laura and Apples 【水题】
- Oracle X2-2 一体机Solaris 平台最佳实践 (文档 ID 2009867.1)
- 机器学习之初生牛犊
- Animation Animate Armture三个动画的使用
- [BZOJ3572][HNOI2014]世界树
- STM32f746G-DISCO开发使用
- 北京雾霾指数再度爆表!创业者们已经纷纷逃离北京
- 如何终止java线程
- 1.3:Union-Find算法-----quick-find算法