CF #632A(A. Grandma Laura and Apples,)数学题
2016-03-03 23:14
330 查看
题意:有n个顾客买老太太的苹果,单价p,每个顾客买老太太所拥有苹果的一半,老太太会对某些顾客优惠即送半个苹果,最后苹果都卖光了,求总共卖了多少钱。
Examples
input
2 10
half
halfplus
output
15
input
3 10
halfplus
halfplus
halfplus
output
55
half表示不送苹果,halfplus即对顾客赠送半个苹果。
分析:从后往前推,由于苹果已卖完,所以最后一个顾客买的时候一定是剩余1个苹果,如果赠送的话,从后往前是1,3,7,15,,,,,
赠半个苹果就是2*n+1,不赠的话就是2*n;
Examples
input
2 10
half
halfplus
output
15
input
3 10
halfplus
halfplus
halfplus
output
55
half表示不送苹果,halfplus即对顾客赠送半个苹果。
分析:从后往前推,由于苹果已卖完,所以最后一个顾客买的时候一定是剩余1个苹果,如果赠送的话,从后往前是1,3,7,15,,,,,
赠半个苹果就是2*n+1,不赠的话就是2*n;
#include<bits/stdc++.h> using namespace std; int main() { string s[42]; int n,p; scanf("%d%d",&n,&p); for(int i=1;i<=n;i++) cin>>s[i]; __int64 sum=(p>>1),num=1; for(int i=n-1;i>0;i--) { if(s[i]=="halfplus") num=(num<<1)+1,sum+=((num>>1)+0.5)*p;//注意要加上0.5,因为num>>1时会丢失0.5,所以要加上 else num<<=1,sum+=(num>>1)*p; } printf("%I64d\n",sum); return 0; }
相关文章推荐
- Android 代码中文字在手机上显示乱码问题解决方法
- Objective-C对象之类对象和元类对象
- Android中AIDL进程间通信
- 专业相框设计(ImageView的堆栈应用)
- Android开发环境下载与搭建
- android textview 莫名其妙 换行了?
- android_TimePicker
- Android内存解析(二)— 详解内存,内部存储和外部存储
- Android学习笔记之Intent(1)
- android 红心 慢慢变红效果 (一般用在收藏或者喜欢上)
- 《Android源码设计模式》读书笔记 (19) 第19章 组合模式
- 移动端前端框架UI库(Frozen UI、WeUI、SUI Mobile)
- 使用Ida 4000 动态调试Android 中的so文件的方式以及技巧
- Android 6.0 权限管理(permission)
- 传值方式(block, 属性,代理 ,单例)
- CADisplayLink
- Android 从源码分析 Android 触摸事件分发过程
- android hal层学习笔记
- Android 触摸事件分发过程
- 通过源码看android系列之AsyncTask