POJ3994 HDU3354 UVALive4736 Probability One水题

Posted tigerisland45

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ3994 HDU3354 UVALive4736 Probability One水题相关的知识,希望对你有一定的参考价值。

Probability One
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 1944 Accepted: 1335

Description

Number guessing is a popular game between elementary-school kids. Teachers encourage pupils to play the game as it enhances their arithmetic skills, logical thinking, and following-up simple procedures. We think that, most probably, you too will master in few minutes. Here’s one example of how you too can play this game: Ask a friend to think of a number, let’s call it n0. Then:

Ask your friend to compute n1 = 3 * n0 and to tell you if n1 is even or odd.

If n1 is even, ask your friend to compute n2 = n1/2. If, otherwise, n1 was odd then let your friend compute n2 = (n1 + 1)/2.

Now ask your friend to calculate n3 = 3 * n2.

Ask your friend to tell tell you the result of n4 = n3/9. (n4 is the quotient of the division operation. In computer lingo, ’/’ is the integer-division operator.)

Now you can simply reveal the original number by calculating n0 = 2 * n4 if n1 was even, or n0 = 2 * n4 + 1 otherwise.

Here’s an example that you can follow: If n0 = 37, then n1 = 111 which is odd. Now we can calculate n2 = 56, n3 = 168, and n4 = 18, which is what your friend will tell you. Doing the calculation 2 * n4 + 1 = 37 reveals n0.

Input

Your program will be tested on one or more test cases. Each test case is made of a single positive number (0 < n0 < 1,000,000).
The last line of the input file has a single zero (which is not part of the test cases.)

Output

For each test case, print the following line:

k. B Q
Where k is the test case number (starting at one,) B is either ’even’ or ’odd’ (without the quotes) depending on your friend’s answer in step 1. Q is your friend’s answer to step 4.

Sample Input

37
38
0

Sample Output

  1. odd 18
  2. even 19

Source

anarc 2009

问题链接POJ3994 HDU3354 UVALive4736 Probability One
问题简述:(略)
问题分析
????这个题是一个水题。然而,计算方法有两种,一是按照题意计算;二是进行计算公式推导后计算,n4=n3/9=3n2/9=3n1/2/9=33n0/2/9=n0/2,另外输出的奇偶是n1的奇偶,而n1=3*n0,所以n1的奇偶同n0的奇偶。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C语言程序(推导计算公式计算)如下:

/* POJ3994 HDU3354 UVALive4736 Probability One */

#include <stdio.h>

int main(void)
{
    int caseno = 0, n;
    while(scanf("%d", &n)  != EOF && n)
        printf("%d. %s %d
", ++caseno, n & 1 ? "odd" : "even", n / 2);

    return 0;
}

AC的C语言程序(按照题意计算)如下:

/* POJ3994 HDU3354 UVALive4736 Probability One */

#include <stdio.h>

int main(void)
{
    int caseno = 0, n, odd;
    while(scanf("%d", &n)  != EOF && n) {
        n *= 3;
        odd = n & 1;
        n >>= 1;
        n *= 3;
        n /= 9;
        printf("%d. %s %d
", ++caseno, odd ? "odd" : "even", n);
    }
    return 0;
}

以上是关于POJ3994 HDU3354 UVALive4736 Probability One水题的主要内容,如果未能解决你的问题,请参考以下文章

POJ1420 HDU1659 UVA196 UVALive5606 SpreadsheetDFS

POJ1598 ZOJ1315 HDU1606 UVA409 UVALive5493 Excuses, Excuses!文本

POJ1573 ZOJ1708 UVA10116 UVALive5334 HDU1035 Robot MotionDFS+BFS

bzoj千题计划210:bzoj2642 | Poj3968 | UVALive 4992| hdu 3761 Jungle Outpost

二分图入门题

UVALive 4223 / HDU 2962 spfa + 二分