uva 100 3n+1 problem
来源:互联网 发布:网络新兴词汇 编辑:程序博客网 时间:2024/05/16 07:55
今天尝试着注册了uva的帐号来试试刷题。记录一下AC的代码
#include "stdio.h"//检查数字的大小来保证从小到大数数 void check(int* i, int* j){ if(*i > *j){ int temp = *i; *i = *j; *j = temp; }}int arr[1000001];int main(){ int i,j;//输入的一堆数字 int cur;//保存当前进行的数字 while(scanf("%d%d",&i,&j) != EOF){ int max = 1; printf("%d %d ",i ,j);//先输出一对数字再进行检查数字 check(&i, &j); for(cur = i; cur<=j; cur++){ //如果已经计算过了就直接赋值来减少运算时间 if(arr[cur] != 0){ if(max < arr[cur]){ max = arr[cur]; } continue; } //基本算法 int count = 1; int temp = cur; while(temp != 1){ if(temp%2 != 0){ temp = 3 * temp + 1; }else{ temp = temp / 2; } count++; } arr[cur] = count; if(count>max){ max = count; } } printf("%d\n",max); }}
0 0
- UVA 100 The 3n + 1 problem
- UVa 100 - The 3n + 1 problem
- UVa 100 - The 3n + 1 problem
- UVa 100 - The 3n + 1 problem
- Uva 100 3n+1problem
- uva 100 The 3n+1 problem
- UVa 100 - The 3n + 1 problem
- UVa 100 The 3n + 1 problem
- uva 100 The 3n + 1 problem
- UVa 100 The 3n + 1 problem
- UVa 100 The 3n + 1 problem
- uva--100 - The 3n + 1 problem
- UVa 100 - The 3n + 1 problem
- UVa 100 - The 3n + 1 problem
- UVa 100 - The 3n + 1 problem
- UVa - 100 - The 3n + 1 problem
- UVa 100 - The 3n + 1 problem
- Uva 100 The 3n+1 problem
- 软件使用表(定期更新 2017-1-24)
- div+css布局
- HDU 3572 Task Schedule
- hdu 1232 畅通工程
- HTML静态页面
- uva 100 3n+1 problem
- OJ 2410: 求n以内奇数的平方和【简单循环】
- mahout剖析
- 忆实习与假期的bili
- HTML页面布局
- HTML注释
- NOIP2014提高组第四题 虫食算
- js编程
- 输入文章,统计各个单词出现次数