CodeForces-632A-Grandma Laura and Apples
2016-03-22 23:17
381 查看
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
2 10
half
halfplus
Output
15
Input
3 10
halfplus
halfplus
halfplus
Output
55
个人赛第三场,又是一道阅读理解题
题意,已知顾客数量n,苹果单价为p,苹果总数未知,顾客买苹果的字符串如果是half,就买走当前数量一半的苹果,如果是halfplus,买走一半苹果的同时会获赠半个苹果(如果一只都是买一半的话,也不可能把苹果卖完)
倒推模拟,从最后入手,获得苹果的总数,然后乘以单价输出。
代码
读题半小时,代码十分钟。。。。。。
下次敢不敢出个韩语的。。
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
个人赛第三场,又是一道阅读理解题
题意,已知顾客数量n,苹果单价为p,苹果总数未知,顾客买苹果的字符串如果是half,就买走当前数量一半的苹果,如果是halfplus,买走一半苹果的同时会获赠半个苹果(如果一只都是买一半的话,也不可能把苹果卖完)
倒推模拟,从最后入手,获得苹果的总数,然后乘以单价输出。
代码
#include <iostream> #include<algorithm> #include<stdio.h> #include<math.h> #include<string> #include<string.h> using namespace std; int cmp(string str1,string str2) { return str1+str2<str2+str1; } int main() { int n; while(scanf("%d",&n)!=EOF) { string str[50005]; for(int i=0; i<n; i++) cin>>str[i]; sort(str,str+n,cmp); for(int i=0; i<n; i++) cout<<str[i]; printf("\n"); } return 0; }
读题半小时,代码十分钟。。。。。。
下次敢不敢出个韩语的。。
相关文章推荐
- Android Stdio程序在虚拟机运行出现enabled ADB integration to be ebabled错误
- 关于android开发自定义view
- iOS 自定义下载进度条
- Android手机录制屏幕及转GIF
- 微信web开发者工具的使用
- 活动的生命周期
- invalid bound statement (not found),大概应该是报mapper.xml中的sql查询和mapper.java中的方法没有绑定成功!
- Activity生命周期
- IOS开发-ObjC-NSString
- Android中简单列表对话框问题
- facebook的图片加载控件SimpleDraweeView的属性
- Android中的软引用、弱引用
- Android数据库框架
- Currying & Partial[applied] function 初体验
- Android动画一:帧动画
- Android Studio找不到R类的几种可能
- Android加载网页输入框无法弹出输入法
- iOS中常见的设计模式(MVC/单例/委托/观察者)
- Android Sensor流程
- Android ListView同一个item显示2列的实现方法(仿2列商品列表)