zoukankan      html  css  js  c++  java
  • 第一次超水(我错了,有难度的)的组队赛!!!The Coco-Cola Store &&Multiple of 17&& Box Game

      The Coco-Cola Store 

    Once upon a time, there is a special coco-cola store. If you return three empty bottles to the shop, you'll get a full bottle of coco-cola to drink. If you have n empty bottles right in your hand, how many full bottles of coco-cola can you drink?

    Input 

    There will be at most 10 test cases, each containing a single line with an integer n ( 1$ le$n$ le$100). The input terminates with n = 0, which should not be processed.

    Output 

    For each test case, print the number of full bottles of coco-cola that you can drink.

    Sample Input 

    3
    10
    81
    0
    

    Sample Output 

    1
    5
    40
    


    Spoiler

    Let me tell you how to drink 5 full bottles with 10 empty bottles: get 3 full bottles with 9 empty bottles, drink them to get 3 empty bottles, and again get a full bottle from them. Now you have 2 empty bottles. Borrow another empty bottle from the shop, then get another full bottle. Drink it, and finally return this empty bottle to the shop!

     水到爆,空瓶子换水问题。

     1 #include <stdio.h>
     2 int main()
     3 {
     4     int n;
     5     while(scanf("%d",&n)==1 && n)
     6     {
     7         int Sum=0;
     8         while(n>=3)
     9         {
    10             Sum+=n/3;
    11             n=n/3+n%3;
    12         }
    13         if(n==2)
    14         {
    15             ++Sum;
    16         }
    17         printf("%d
    ",Sum);
    18     }
    19     return 0;
    20 }
      Multiple of 17 

    Theorem: If you drop the last digit d of an integer n (n$ ge$10), subtract 5d from the remaining integer, then the difference is a multiple of 17 if and only if n is a multiple of 17.

    For example, 34 is a multiple of 17, because 3-20=-17 is a multiple of 17; 201 is not a multiple of 17, because 20-5=15 is not a multiple of 17.

    Given a positive integer n, your task is to determine whether it is a multiple of 17.

    Input 

    There will be at most 10 test cases, each containing a single line with an integer n ( 1$ le$n$ le$10100). The input terminates with n = 0, which should not be processed.

    Output 

    For each case, print 1 if the corresponding integer is a multiple of 17, print 0 otherwise.

    Sample Input 

    34
    201
    2098765413
    1717171717171717171717171717171717171717171717171718
    0
    

    Sample Output 

    1
    0
    1
    0
    

     用int数组来进行大数运算。

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<algorithm>
     4 #include<string.h>
     5 #include<math.h>
     6 using namespace std;
     7 int main()
     8 {
     9     int a1[100005],n,d,i,w;
    10     char a[100005];
    11     while(scanf("%s",a)!=EOF)
    12     {
    13         memset(a1,0,sizeof(a1));
    14         n=strlen(a);
    15         if(n==1&&a[0]=='0')
    16             break;
    17         d=a[n-1]-'0';
    18         d=5*d;
    19         n--;
    20         for(i=0;i<n;i++)
    21         {
    22             a1[n-1-i]=a[i]-'0';//把字符串数组变成整型数组(顺序调反便于进行减法)
    23         }
    24         if(n<=4)
    25         {
    26             w=a1[3]*1000+a1[2]*100+a1[1]*10+a1[0];
    27             w=abs(w-d);
    28             if(w%17==0)
    29                 printf("1
    ");
    30             else
    31                 printf("0
    ");
    32         }
    33         else
    34         {if(d<10)
    35         {
    36             a1[0]=a1[0]+10-d;
    37             if(a1[0]>9)
    38                 a1[0]=a1[0]%10;
    39             else a1[1]=a1[1]-1;
    40         }
    41         else
    42         {
    43             a1[0]=a1[0]+10-d%10;
    44             if(a1[0]>9)
    45                 a1[0]=a1[0]%10;
    46             else a1[1]=a1[1]-1;
    47             a1[1]=a1[1]+10-d/10;
    48             if(a1[1]>9)
    49                 a1[1]=a1[1]%10;
    50             else a1[2]=a1[2]-1;
    51         }
    52         for(i=n-1;;i--)
    53         {
    54             if(a1[i]==0)
    55                 n--;
    56             else
    57                 break;
    58         }
    59         for(;;)
    60         {
    61             for(i=n-1;i>=1;i--)
    62         {
    63                     a1[i-1]=(a1[i]*10+a1[i-1])%17;//这里还只要看余数就行了。
    64         }
    65         if(a1[0]!=0)
    66             {printf("0
    ");break;}
    67             if(a1[0]==0)
    68                 {printf("1
    ");break;}
    69         }}
    70     }
    71 return 0;
    72     }
      Box Game 

    There are two identical boxes. One of them contains n balls, while the other box contains one ball. Alice and Bob invented a game with the boxes and balls, which is played as follows:

    Alice and Bob moves alternatively, Alice moves first. For each move, the player finds out the box having fewer number of balls inside, and empties that box (the balls inside will be removed forever), and redistribute the balls in the other box. After the redistribution, each box should contain at least one ball. If a player cannot perform a valid move, he loses. A typical game is shown below:

    epsfbox{p12293.eps}

    When both boxes contain only one ball, Bob cannot do anything more, so Alice wins.


    Question: if Alice and Bob are both clever enough, who will win? Suppose both of them are very smart and always follows a perfect strategy.

    Input 

    There will be at most 300 test cases. Each test case contains an integer n ( 2$ le$n$ le$109) in a single line. The input terminates by n = 0.

    Output 

    For each test case, print a single line, the name of the winner.

    Sample Input 

    2
    3
    4
    0
    

    Sample Output 

    Alice
    Bob
    Alice

    当分成俩部分时,下一个只能取较大者来进一步分!

     1 #include <stdio.h>
     2 #include<iostream>
     3 using namespace std;
     4 int main()
     5 {
     6     int n,sum;
     7     while(~scanf("%d",&n)&&n)
     8     {
     9         sum=1;
    10         for(;;)
    11         {
    12             sum=sum*2+1;
    13             if(n<=sum)
    14                 break;
    15         }
    16         if(n==sum)
    17             printf("Bob
    ");
    18         else
    19             printf("Alice
    ");
    20     }
    21     return 0;
    22 }

    找规律:(本人这方面比较差)

    首先分析简单的情况,数字代表最大堆,2必胜,3必输,4必胜,……其实偶数必胜是显然的,但奇数就不好说了,于是我们换个角度考虑。

        如果说3必输的话,那么最后能把最大堆是3的情况留给Bob那么自己必然会赢,而能确保最大堆是3的情况就只有4、5、6了,而对于7,无论自己如何设置,都会把4、5、6其中的一个留给Bob,故自己必输。

        同理,7必输的话,把7留给Bob就必胜,于是……

        这样推完,其实Bob能赢的情况就是在n=2^k-1(k = 2, 3, 4,…)的时候,其他时候Alice都是必胜的。

  • 相关阅读:
    面向对象之多态,property
    描述符
    day23 面向对象之继承
    day22面向对象
    os模块
    logging日志模块,四种方式
    Linux 如何测试 IO 性能(磁盘读写速度)
    Vi命令:如何删除全部内容
    cdnbest如何查看站点操作日志(同步日志)
    Linux查找含有某字符串的所有文件
  • 原文地址:https://www.cnblogs.com/tt123/p/3215650.html
Copyright © 2011-2022 走看看