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

首頁 > 學院 > 開發(fā)設計 > 正文

poj1207

2019-11-11 02:39:25
字體:
供稿:網(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ī)律計算i和j之間迭代次數(shù)最多的數(shù),最后要計算到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ā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 湘乡市| 巨鹿县| 仙居县| 嘉义市| 余姚市| 涿鹿县| 新和县| 平阳县| 黄骅市| 盈江县| 高雄县| 融水| 法库县| 明星| 上栗县| 澄迈县| 新密市| 永泰县| 合阳县| 江源县| 内乡县| 工布江达县| 织金县| 包头市| 汉寿县| 岑巩县| 拉萨市| 紫金县| 隆昌县| 米易县| 仁化县| 谢通门县| 潼南县| 宝丰县| 新绛县| 鄢陵县| 乳山市| 喜德县| 汝阳县| 孙吴县| 武城县|