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

Source: Internet
Author: User

    • Time: 2016-03-25-23:50:29
    • Title Number: [2016-03-26][codeforces][632][a][grandma Laura and Apples]
    • The main topic: There are n guests, each guest to buy half of the apples, if the apple is odd, the extra half of the apples to the guests, is known to buy a guest whether to receive more apples, ask how many dollars should be received in total
    • Analysis:
      • When the last Apple was left, the guest only bought half an apple and sent half an apple, so the last one must be plus,
      • Direct calculation of the number of all apples, and the number of complimentary apples, the final total
  
  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. }


From for notes (Wiz)

[2016-03-26][codeforces][632][a][grandma Laura and Apples]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.