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

Posted 红洋

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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. }




以上是关于[2016-03-26][codeforces][632][A][Grandma Laura and Apples]的主要内容,如果未能解决你的问题,请参考以下文章

[转载]ubuntu Atheros Communications Device 1083 驱动

如果用户已经使用 facebook 登录,则使用 swift 调用 segue

无法在 AWS Opsworks 上使用 Chef 12 查找 Chef 社区食谱

阻塞队列模型和线程池

codeforces上怎么看测试数据

如何看codeforces做了多少题