求助
  • 板块灌水区
  • 楼主dsj2012
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/12/21 09:35
  • 上次更新2024/12/21 12:32:28
查看原帖
求助
996107
dsj2012楼主2024/12/21 09:35

Ackermann Functions

本道题目我没有账号请求那位有账号的大佬帮我交一下看看对不对?必关

#include<bits/stdc++.h>
using namespace std;
int l,r;
int a[10000005];
int check(int x){
	if(x == 1){
		return 0;
	}
	if(a[x] != 0){
		return a[x];
	}
	if(x % 2 == 0){
		a[x] = check(x / 2) + 1;
	}else{
		a[x] = check(x * 3 + 1) + 1;
	}
	return a[x];
}
int main(){
	while(cin >> l >> r && l && r){
		if(l > r)swap(l , r);
		int x = 0,maxn = 0;
		for(int i = l ; i <= r ; i ++){
			a[i] = check(i);
			if(maxn < a[i]){
				maxn = a[i];
				x = i;
			}
		}
		printf("Between %d and %d, %d generates the longest sequence of %d values.\n" , l , r , x , maxn);
	}
	return 0;
} 
2024/12/21 09:35
加载中...