解题思路:
还是原来的套路,,先得出所有结果,,
然后输入,,筛选,,输出。。
注意事项:
x 推荐使用long long int,,
否则i==113383,i==134379,i==138367时会爆int,,虽然测试的数据都是小于等于1000的
参考代码:
#include <stdio.h> int a[1000001]; int main() { int m, n, max; long long int x; int count; int temp, i; for (i = 1; i <= 1000000; i++) { x = i; count = 1; while (x != 1) { if (x % 2 == 0) x /= 2; else x = x * 3 + 1; count++; } a[i] = count; } while (scanf("%d%d", &m, &n) != EOF) { printf("%d %d ", m, n); if (m > n) { temp = m; m = n; n = temp; } max = 0; for (i = m; i <= n; i++) { max = a[i] > max ? a[i] : max; } printf("%d\n", max); } return 0; }
0.0分
3 人评分
#include<iostream> using namespace std; int three(int a,int b); int main() { int a,b; while(cin>>a) { cin>>b; int t; if(a>b) { t=a; a=b; b=t; } three(a,b); } return 0; } int three(int a,int b) { int i,n=0,max=0; for( i=a;i<=b;i++) { n=1; int j=i; while(j!=1) { if(j%2==0) j=j/2; else j=j*3+1; n++; } if(n>max) max=n; } cout<<a<<" "<<b<<" "<<max<<endl; } //我的为毛不过?我看别人的int能通过啊
ET 2019-01-27 19:20:42 |
读一下题。。。For each pair of input integers i and j, output i, j in the same order in which they appeared in the input.
C二级辅导-分段函数 (C语言代码)浏览:768 |
母牛的故事 (C语言代码)浏览:1135 |
校门外的树 (C语言代码)浏览:1076 |
简单的a+b (C语言代码)浏览:536 |
最长单词 (C语言代码)浏览:1291 |
【计算直线的交点数】 (C语言代码)浏览:1373 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)from DQM浏览:628 |
数对 (C语言代码)浏览:685 |
Hello, world! (C语言代码)浏览:794 |
GC的苦恼 (C语言代码)浏览:612 |