读书人

HDU1032:The 3n + 一 problem

发布时间: 2013-02-28 11:33:09 作者: rapoo

HDU1032:The 3n + 1 problem
Problem DescriptionInputOutputSample InputSample Output#include <iostream>using namespace std;int main(){ int a,b,t,i,max; while(cin >> a >> b) { cout << a << " " << b << " "; if(a>b)//大小不确定 { t = a; a = b; b = t; } max = 0; for(i = a; i<=b; i++) { int n = i, sum = 1; while(n-1)//等于1时就结束 { if(n%2) n = 3*n+1; else n = n/2; sum++; } if(sum>max) max = sum; } cout << max << endl; } return 0;}

1楼foundare_202昨天 15:05
了解下nn方蝶SP2010

读书人网 >编程

热点推荐