UVA 100
2013-04-10 21:21
369 查看
Time limit: 3.000 seconds |
首先 , 输入的两个数不一定谁大谁小 , 但你输出时还要按原顺序 ,
其次 , 中间变量 n 要 long long
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int st , en , max , sum;
//freopen("in.txt" , "r" , stdin);
while(cin >> st >> en)
{
max = 0;
int a , b;
if(st < en)
{
a = st ;
b = en ;
}
else
{
a = en;
b = st;
}
for(int i = a ; i <= b ; i ++)
{
sum = 1;
long long n = i;
while(n != 1)
{
if(n % 2 == 1)
{
n = 3 * n + 1;
}
else
{
n /= 2;
}
sum ++;
}
if(sum > max)max = sum;
}
printf("%d %d %d\n", st , en , max);
}
return 0;
}
相关文章推荐
- UVA100
- UVA 100 - The 3n+1 Problem
- uva 100 The 3n + 1 problem
- uva100 The 3n + 1 problem
- UVA 100 The 3n + 1 problem
- UVA 100 && HDU 1032 The 3n+1问题 (扑街题)
- UVa 100 - The 3n + 1 problem
- UVa 100 / HDU 1032 / POJ 1207 The 3n + 1 problem (数论&Collatz序列周期)
- UVa 100 - The 3n + 1 problem
- UVa 100 - The 3n + 1 problem
- 近期简单题目小结 UVA 100+HDU 2007+URAL 1084+Poj 1152+UVA 10042+UVA 11752+UVA 10780
- ACM UVa 算法题100, 101, 103, 104, 112, 10405解法
- The 3n + 1 problem (Uva 100)
- UVA 100 The 3n + 1 problem
- UVA100 POJ1207 HDU1032 The 3n + 1 problem【水题】
- UVA100- The 3n + 1 problem
- UVa 100 The 3n + 1 problem
- 1.6.1 3n+1问题 UVA100
- UVA-100
- UVa OJ 100-The 3n+1 Problem