[2016-03-26][codeforces][632][A][Grandma Laura and Apples]

  • 时间:2016-03-25 23:50:29 星期五

  • 题目编号:[2016-03-26][codeforces][632][A][Grandma Laura and Apples]

  • 题目大意:有n的客人,每个客人都来买一半的苹果,如果苹果为奇数,就把多出来的半个苹果送给客人,已知买个客人是否收到更多苹果,问总共应该收到多少元

  • 分析:

    • 最后剩下一个苹果的时候,客人只买半个苹果,送半个苹果,所以最后一个一定是plus,
    • 直接计算所有苹果的数目,和赠送的苹果数目,求最后总值
  1. #include <cstdio>
  2. using namespace std;
  3. typedef long long LL;
  4. const int maxn = 50;
  5. int a[maxn];
  6. int main(){
  7. int n,p;
  8. char op[20];
  9. scanf("%d%d",&n,&p);
  10. for(int i = 0; i < n;++i){
  11. scanf("%s",op);
  12. a[i] = op[4] != ‘\0‘;
  13. }
  14. LL cnt = 0,bcnt = 0;
  15. for(int i = n - 1;i >= 0 ;--i){
  16. if(a[i]){
  17. cnt = cnt * 2 + 1;
  18. ++bcnt;
  19. }else{
  20. cnt = cnt * 2;
  21. }
  22. }
  23. printf("%I64d\n",cnt*p - bcnt * (p / 2));
  24. return 0;
  25. }

来自为知笔记(Wiz)

时间: 2024-08-30 03:40:17

[2016-03-26][codeforces][632][A][Grandma Laura and Apples]的相关文章

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 standard input output standard output Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma

Educational Codeforces Round 9 -- A - Grandma Laura and Apples

题意: 外祖母要卖苹果,(有很多但不知道数量),最终所有苹果都卖光了! 有n个人买苹果,如果那个人是half,他就买所有苹果的一半,如果那个人是halfplus,则他买当前苹果数量的一半,Laura还会送半个苹果!问最多能赚多少钱? 思路: 会后一个人一定是halfplus,否则苹果卖不完,所以最后一个人买的时候已经只剩一个.然后从后往前推. 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #

CodeForces 632C Grandma Laura and Apples (模拟)

题意:有n个人买苹果,当苹果剩余偶数时买走一半,当苹果剩余奇数时,先买走一半,再用半价买走一个苹果,最终苹果恰好卖完.农民收入为多少. 析:反向模拟. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include &l

CF632A Grandma Laura and Apples

#include<bits/stdc++.h> using namespace std; long long n,p,ans=0,total=0,apple=0; int main() { string a[100000]; cin>>n>>p; p=p>>1; for(int i=1;i<=n;i++) { cin>>a[i]; } for(int i=n;i>=1;i--) { total=total*2; if(a[i]==&q

Murano Weekly Meeting 2016.07.26

Meeting time: 2016.July.26 1:00~2:00 Chairperson:  Nikolay_St, from Mirantis Meeting summary: 1.Mascot mascot candidates: * muraena 海鳝 * orca 逆戟鲸 * winged lion 有翼的狮子 * racoon 浣熊 * glasscrab 龙虾 * other stuff 其他东西 Link:  https://etherpad.openstack.org/

分布式技术一周技术动态 2016.03.20

分布式系统实践 1. 基于Mesos和Docker的分布式计算平台 https://mp.weixin.qq.com/s?__biz=MzAxMDgzOTA2Mw==&mid=402769128&idx=1&sn=cea3ad1357bd9312acf1768c0a493bfd&scene=1&srcid=0318BTuxT0fsFYwPjpeyuDOa&key=710a5d99946419d90fbc1e7600cce055b6e997d6afafc74c

http://stormzhang.com/opensource/2016/06/26/android-open-source-project-recommend1/

转载自:http://stormzhang.com/opensource/2016/06/26/android-open-source-project-recommend1/ 推荐他的所有博文~ 图片加载几乎是任何 Android 项目中必备的需求,而图片加载的开源库也越来越多,我们姑且在 GitHub 上搜索下 android image 关键字,出来的前五个按照 Star 数排序的项目如下: 可以看到前四个是大家比较熟知的图片加载库,有 UniversalImageLoader.Picass

uboot.2016.03 在mini2440上norfalsh启动

本人有点懒惰,直接在smdk2410的基础上进行修改 (note :红色字体表示修改内容,蓝色字体表示增加内容) 1. 顶层的makefile 在247行 添加如下两条语句 :   ARCH :=arm     CROSS_COMPILE :=arm-linux- 2 修改始终频率 打开 u-boot-2016.03/arch/arm/cpu/arm920t/start.S 第77行 #if defined(CONFIG_S3C2410) #if defined(CONFIG_S3C2440)

2016.9.26小程序---数据库练习2

1 -- createnobel, 1, 50 2 DROP TABLE nobel; 3 CREATE TABLE nobel( 4 yr INT -- 年份 5 ,SUBJECT VARCHAR(15) -- 奖项 6 ,winner VARCHAR(50) -- 获奖者 7 )DEFAULT CHARSET=utf8; 8 9 GO 10 -- tabnobel, 1, 50 11 INSERT INTO nobel VALUES (1901,'Chemistry','Jacobus H.