国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

poj1207

2019-11-11 01:13:27
字體:
供稿:網(wǎng)友

題目大意:

按照 1.input n 2.PRint n 3.if n = 1 then STOP 4.if n is odd then n <– 3n+1 5.else n <– n/2 6.GOTO 2 規(guī)律計(jì)算i和j之間迭代次數(shù)最多的數(shù),最后要計(jì)算到1

解題思路:

簡單模擬

代碼如下:

#include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>int cycle(int n){ int count=1,m=n; while(m!=1) { if(m%2) { m=3*m+1; count++; } else { m=m/2; count++; } } return count;}int main(){ int i,j; int count,max; int k; while(scanf("%d%d",&i,&j)!=EOF) { max=0; if(i<j) { max=cycle(i); for(k=i+1;k<=j;k++) { count=cycle(k); if(count>max) { max=count; } } } else { max=cycle(j); for(k=j+1;k<=i;k++) { count=cycle(k); if(count>max) { max=count; } } } printf("%d %d %d/n",i,j,max); } return 0;}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 东安县| 姚安县| 司法| 茂名市| 滦平县| 怀柔区| 禹州市| 新余市| 临武县| 右玉县| 任丘市| 侯马市| 武胜县| 仙游县| 桑植县| 威宁| 阜南县| 辉南县| 郎溪县| 卢湾区| 沧源| 灵武市| 六枝特区| 尉犁县| 武山县| 南宁市| 都兰县| 尉氏县| 河曲县| 荆门市| 南岸区| 广平县| 吴忠市| 长武县| 建水县| 潮州市| 辽宁省| 中西区| 饶阳县| 花莲县| 中卫市|