解题思路:
还是原来的套路,,先得出所有结果,,
然后输入,,筛选,,输出。。
注意事项:
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.