POJ 3994:Probability One
2015-10-01 11:08
183 查看
Probability One
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
Sample Output
把整个过程换算完了就是把原数除以2。
代码:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1674 | Accepted: 1151 |
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
把整个过程换算完了就是把原数除以2。
代码:
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> using namespace std; int main() { int num,i=1; while(cin>>num) { if(num==0) break; cout<<i<<". "; i++; if(num%2) cout<<"odd "; else cout<<"even "; cout<<num/2<<endl; } return 0; }
相关文章推荐
- 例题5.7 等价性证明 LA4287
- Android 微信支付开发
- MFC学习
- py模块的加载
- 《C++primer(第五版)》学习之路-第十三章:拷贝控制
- 完成一个H.265/HEVC码流分析工具
- ThinkPHP代码和程序目录结构与MVC架构
- 在eclipse中配置openCV
- 构建分别基于mysql服务器存储、文本存储用户账号密码的vsftpd服务器
- 快速准确地将CNKI数据导入Endnote
- org.apache.commons扩展容器中的Predicate类
- Java ArrayList和Vector的区别
- ubuntu打开终端的两种简单方式
- CompletionPort
- SpriteBuilder中如何固定两个互不接触的物理物体?
- Servlet 3.0异步处理
- uboot.lds 链接脚本语法规则
- SpriteBuilder中如何固定两个互不接触的物理物体?
- SpriteBuilder中如何固定两个互不接触的物理物体?
- Spark DAGScheduler 功能及源码解析