博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3994:Probability One
阅读量:5966 次
发布时间:2019-06-19

本文共 2188 字,大约阅读时间需要 7 分钟。

Probability One
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1674   Accepted: 1151

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 n
0. 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 n
0 = 37, then n
1 = 111 which is odd. Now we can calculate n
2 = 56, n
3 = 168, and n
4 = 18, which is what your friend will tell you. Doing the calculation 2 * n
4 + 1 = 37 reveals n
0.

Input

Your program will be tested on one or more test cases. Each test case is made of a single positive number (0 < n
0 < 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

37380

Sample Output

1. odd 182. even 19

把整个过程换算完了就是把原数除以2。

代码:

#include 
#include
#include
#include
#include
#include
using namespace std;int main(){ int num,i=1; while(cin>>num) { if(num==0) break; cout<
<<". "; i++; if(num%2) cout<<"odd "; else cout<<"even "; cout<

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/lightspeedsmallson/p/4899549.html

你可能感兴趣的文章
Git协作流程(转)
查看>>
iOS UI-自动布局(Autoresizing)
查看>>
i.e., e.g., etc.
查看>>
计算机视觉与模式识别代码合集第二版three
查看>>
Android studio SweetAlert for Android
查看>>
sql中的CHARINDEX和暂时表
查看>>
火炬之光模型导出(Unity载入火炬之光的模型)
查看>>
git忽略文件【转】
查看>>
Web上的支持的图片格式以及它们之间的区别
查看>>
随意而为
查看>>
jQuery监听文本框值改变触发事件(propertychange)
查看>>
[LeetCode] Flip Game II 翻转游戏之二
查看>>
最简单的基于Flash的流媒体示例:网页播放器(HTTP,RTMP,HLS)
查看>>
IOS开发中的几种设计模式
查看>>
Json——使用Json jar包实现Json字符串与Java对象或集合之间的互相转换
查看>>
HDU--2040
查看>>
zepto返回顶部动画
查看>>
CVBS视频信号解析
查看>>
必要时进行保护性拷贝
查看>>
Codeforces Round #356 (Div. 1) D. Bear and Chase 暴力
查看>>