40pts MLE 求助
查看原帖
40pts MLE 求助
529722
Dream_Creator卷王楼主2022/10/23 21:51
#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
ull n,k;
void f(ull x,ull cishu){
	if(cishu<=0){
		cout<<x;
		exit(0);
	}
	if(x%3==0){
		if(cishu<3){
			cout<<x+cishu;
			exit(0);
		}
		x+=3;
		x/=3;
		f(x,cishu-3);
	}else if(x%3==1){
		if(cishu<2){
			cout<<x+cishu;
			exit(0);
		}
		x+=2;
		x/=3;
		f(x,cishu-2);
	}else{
		x++;
		x/=3;
		f(x,cishu-1);
	}
}
int main(){
	cin>>n>>k;
	f(n,k);
	return 0;
}

递归思想,kk101810^{18} 就 MLE 过不去。

暴力思想,TLE 过不去。

2022/10/23 21:51
加载中...