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

首頁 > 學院 > 開發設計 > 正文

poj1207

2019-11-11 00:44:02
字體:
來源:轉載
供稿:網友

題目大意:

按照 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 規律計算i和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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 天等县| 宁都县| 阳原县| 健康| 崇信县| 沙河市| 齐齐哈尔市| 仙居县| 沙雅县| 平原县| 会宁县| 招远市| 修水县| 新泰市| 宁津县| 新绛县| 肥乡县| 南雄市| 无棣县| 鄂温| 华容县| 通河县| 剑阁县| 马尔康县| 中卫市| 美姑县| 高清| 石景山区| 涿鹿县| 浮梁县| 马山县| 云龙县| 维西| 运城市| 井研县| 海安县| 阿坝县| 常熟市| 贵溪市| 宁国市| 郓城县|