社区讨论

神秘随机化算法求hack

P2431正妹吃月饼参与者 7已保存回复 9

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
9 条
当前快照
1 份
快照标识符
@mhphxfs8
此快照首次捕获于
2025/11/08 07:37
4 个月前
此快照最后确认于
2025/11/09 02:28
4 个月前
查看原帖
rt,我的乱搞代码过了
CPP
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
const int N=100;
ull p[N],a,b,ans=0;
priority_queue<ull> q;
void SA(){
	int cnt=6e5;
	while(cnt--){
		random_shuffle(p,p+64);
		ull tot=0,dnt=0;
		for(int i=0;i<=63;i++){
			tot+=p[i];dnt++;
			if(tot>b)tot-=p[i],dnt--;
			if(tot>=a&&tot<=b)ans=max(ans,dnt);
		}
	}
}
int main(){
	srand(time(0));
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>a>>b;p[0]=1ll;
	for(int i=1;i<=63;i++)p[i]=p[i-1]*2ll;
	SA();
	cout<<ans<<"\n";
	return 0;
}

回复

9 条回复,欢迎继续交流。

正在加载回复...