HDU_3354 Probability One
来源:互联网 发布:位面淘宝txt八零 编辑:程序博客网 时间:2024/06/07 00:22
Probability One
Problem 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:
1. Ask your friend to compute n1 = 3 * n0 and to tell you if n1 is even or odd.
2. 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.
3. Now ask your friend to calculate n3 = 3 * n2.
4. 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.)
5. 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.
Then:
1. Ask your friend to compute n1 = 3 * n0 and to tell you if n1 is even or odd.
2. 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.
3. Now ask your friend to calculate n3 = 3 * n2.
4. 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.)
5. 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.)
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.
Note: There is a blank space before B.
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.
Note: There is a blank space before B.
Sample Input
37380
Sample Output
1. odd 182. even 19
//位运算水题 #include<stdio.h>int main(){ int count=0,n; while(scanf("%d",&n),n!=0) { printf("%d. ",++count); if(n&1) printf("odd "); //奇数 else printf("even "); if(n&1) printf("%d\n",(n-1)>>1); // 除以2,右移一位 else printf("%d\n",n>>1); } return 0;}
0 0
- HDU_3354 Probability One
- POJ 3994:Probability One
- 北大ACM poj3994 Probability One
- POJ 3994 Probability One G++
- 哈理工oj 1001 Probability One
- Probability
- Probability
- Probability
- Probability
- Probability
- probability
- Probability
- Probability
- Probability: Expectation
- Probability Theory
- probability density
- Probability|Given
- Probability 2131
- Win8中解决组件服务中右键我的电脑没有属性的问题
- 关于org.apache.jasper.JasperException: Unable to compile class for JSP
- 需求案例积累一
- 商品分类筛选条件建模数据表的设计
- WdatePicker日历添加事件,在任意月改变时处理日期事件
- HDU_3354 Probability One
- 内外连接inner outer
- 自定义模型SearchModel ------ Model-View-Control(MVC)架构(9)
- 第一个Makefile的编写(原始到模式化)
- HDU1873 优先队列
- Objective-C语法之Category的使用
- Oracle专用服务器与共享服务器的区别
- 什么叫熟悉TCP/IP协议?
- Tomcat性能调优