ET


私信TA

用户名:wbc

访问量:59449

签 名:

人生苦短,我TM直接py

等  级
排  名 62
经  验 10356
参赛次数 3
文章发表 68
年  龄 0
在职情况 学生
学  校 东北大学
专  业 计算机科学与技术

  自我简介:

自2020起转python了。。。 C++兼容C,所以不要问为什么我所有的提交都是C++的.... 不AC,毋宁死,代码越短越好,思路越清奇越好hhhhhhhh

解题思路:
还是原来的套路,,先得出所有结果,,

然后输入,,筛选,,输出。。



注意事项:
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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区

这也算题解?这不就是常规解法吗?没有什么算法可言。。
2019-11-12 21:49:31
int 的范围不是2148473647吗?  为什么会爆呢???
2019-08-07 17:29:49
#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能通过啊
2019-01-24 16:30:44
  • «
  • 1
  • »