国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 霞浦县| 上思县| 建阳市| 平顶山市| 洛隆县| 长泰县| 观塘区| 元江| 额敏县| 平舆县| 平远县| 浮山县| 丹东市| 枞阳县| 绍兴市| 昌图县| 怀安县| 鄯善县| 邵东县| 准格尔旗| 永川市| 三门峡市| 延安市| 武宣县| 饶河县| 双桥区| 九江市| 肇庆市| 昌平区| 闽清县| 鲁甸县| 高阳县| 和田县| 昂仁县| 金川县| 宁强县| 康定县| 马关县| 札达县| 德令哈市| 会同县|