hdu4484(模拟)
来源:互联网 发布:淘宝延迟收货可以几单 编辑:程序博客网 时间:2024/05/17 02:33
Hailstone HOTPO
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 426 Accepted Submission(s): 258
Problem Description
The hailstone sequence is formed in the following way:
(1) If n is even, divide it by 2 to get n'
(2) If n is odd, multiply it by 3 and add 1 to get n'
It is conjectured that for any positive integer number n, the sequence will always end in the repeating cycle: 4, 2, 1, 4, 2, 1,... Suffice to say , when n == 1, we will say the sequence has ended.
Write a program to determine the largest value in the sequence for a given n.
(1) If n is even, divide it by 2 to get n'
(2) If n is odd, multiply it by 3 and add 1 to get n'
It is conjectured that for any positive integer number n, the sequence will always end in the repeating cycle: 4, 2, 1, 4, 2, 1,... Suffice to say , when n == 1, we will say the sequence has ended.
Write a program to determine the largest value in the sequence for a given n.
Input
The first line of input contains a single integer P, (1<= P <= 100000), which is the number of data set s that follow. Each data set should be processed identically and independently.
Each data set consists of a single line of input consisting of two space separated decimal integers. The first integer is the data set number. The second integer is n, (1 <= n <= 100,000), which is the starting value.
Each data set consists of a single line of input consisting of two space separated decimal integers. The first integer is the data set number. The second integer is n, (1 <= n <= 100,000), which is the starting value.
Output
For each data set there is a single line of output consisting of the data set number, a single space, and the largest value in the sequence starting at and including n.
Sample Input
41 12 33 99994 100000
Sample Output
1 12 163 1012484 100000
Source
Greater New York 2012
Recommend
liuyiding
大水题。模拟过程。
#include<iostream>#include<cstdio>using namespace std;int main(){int cas,tag;__int64 n,Max;cin>>cas;while(cas--){scanf("%d %I64d",&tag,&n);Max=n;while(n!=1){if(n%2)n=3*n+1;if(n>Max)Max=n;n/=2;}printf("%d %I64d\n",tag,Max);}return 0;}
- hdu4484(模拟)
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟:
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟
- 模拟
- NYOJ-77-开灯问题-2013年6月29日12:20:40
- Currency Exchange
- 關於 Windows RS-232C 串列通訊經驗談
- 淘宝海量数据库之一
- NYOJ-276-比较字母大小-2013年7月3日15:28:20
- hdu4484(模拟)
- Emacs基本操作
- cocos2d-x2.1.2精灵表单与表单编辑器
- NYOJ-457-大小写互换-2013年7月25日08:51:17
- 最小表示法求两个字符串是否循环相等
- quartz代码
- Stockbroker Grapevine
- llinux根文件系统/etc/passwd文件详解
- NYOJ-75-日期计算-2013年7月25日10:26:18