POJ 3994:Probability One
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1674 | Accepted: 1151 |
Description
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
The last line of the input file has a single zero (which is not part of the test cases.)
Output
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;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 3994:Probability One的更多相关文章
- POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)
http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- POJ 1459:Power Network(最大流)
http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...
- POJ 3436:ACM Computer Factory(最大流记录路径)
http://poj.org/problem?id=3436 题意:题意很难懂.给出P N.接下来N行代表N个机器,每一行有2*P+1个数字 第一个数代表容量,第2~P+1个数代表输入,第P+2到2* ...
- POJ 2195:Going Home(最小费用最大流)
http://poj.org/problem?id=2195 题意:有一个地图里面有N个人和N个家,每走一格的花费是1,问让这N个人分别到这N个家的最小花费是多少. 思路:通过这个题目学了最小费用最大 ...
- POJ 3281:Dining(最大流)
http://poj.org/problem?id=3281 题意:有n头牛,f种食物,d种饮料,每头牛有fnum种喜欢的食物,dnum种喜欢的饮料,每种食物如果给一头牛吃了,那么另一个牛就不能吃这种 ...
- POJ 3580:SuperMemo(Splay)
http://poj.org/problem?id=3580 题意:有6种操作,其中有两种之前没做过,就是Revolve操作和Min操作.Revolve一开始想着一个一个删一个一个插,觉得太暴力了,后 ...
- POJ 3237:Tree(树链剖分)
http://poj.org/problem?id=3237 题意:树链剖分.操作有三种:改变一条边的边权,将 a 到 b 的每条边的边权都翻转(即 w[i] = -w[i]),询问 a 到 b 的最 ...
- POJ 2763:Housewife Wind(树链剖分)
http://poj.org/problem?id=2763 题意:给出 n 个点, n-1 条带权边, 询问是询问 s 到 v 的权值, 修改是修改存储时候的第 i 条边的权值. 思路:树链剖分之修 ...
随机推荐
- 《C Primer Plus(第6版)(中文版)》普拉达(作者)epub+mobi+azw3
内容简介 <C Primer Plus(第6版)中文版>详细讲解了C语言的基本概念和编程技巧. <C Primer Plus(第6版)中文版>共17章.第1.2章介绍了C语言编 ...
- u盘装完centos系统恢复
1.使用windows的cmd窗口,执行diskpart命令 2.执行 list disk命令,查看u盘 3.执行 select disk 2,选中u盘,注意,这里的2是我自己的显示,千万不要选错 4 ...
- js网页拉起支付宝支付
js网页唤起支付宝进行支付 在做uni-app项目中,打包成 ios App的时候,为了绕过苹果支付的审核,所以用的 webview 加载支付宝的网页支付,进行付款 具体实现流程: 前端通过 url ...
- Lesson 47 The great escape
What is one of the features of modern camping where nationality is concerned? Economy is one powerfu ...
- javac导出参考文档报错 错误: 编码GBK的不可映射字符”
- PostgreSQL数据库-抽奖sql
select * from users order by random();--会进行随机排序,每次运行都会返回不同的结果 select * from users order by random() ...
- PHP-WebShell-Bypass-WAF
PHP-WebShell-Bypass-WAF PHP WebShell 一句话的结构是:输入和执行,这是经典的PHP 一句话代码: <?php eval($_GET['test']); ?&g ...
- Saul's Blog
2019Falg完成情况 - 脱贫脱单不脱发(已完成) - 买辆帕拉梅拉 (已完成) - 不再是个蒟蒻(已完成) - 来一场说走就走的旅行(已完成) - 停止口嗨(未完成) ᑋᵉᑊᑊᵒ ᵕ̈ ₂₀₂₀ ...
- Dive into re Module in Python
Dive into RE in Python Standard re module in python is powerful to handle text manipulation,such as ...
- JAVAWEB limit 分页 (转载)
原文来自于 https://www.jianshu.com/p/553fc76bb8eb 作者写的很不错 只是为了自己方便学习转载的 代码我就不贴了 我是 Oracle 要改一些代码 原 ...