国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 黄平县| 宁化县| 井研县| 昌乐县| 山丹县| 黑水县| 武乡县| 丹江口市| 定州市| 玉树县| 永靖县| 曲松县| 娱乐| 奈曼旗| 喀喇| 息烽县| 五大连池市| 且末县| 马尔康县| 内江市| 达孜县| 山东省| 竹北市| 泸溪县| 山阳县| 遂平县| 尉犁县| 民乐县| 保德县| 万安县| 和龙市| 辽中县| 新闻| 久治县| 界首市| 固阳县| 湛江市| 大同市| 云梦县| 天等县| 富源县|