专栏文章

【1】做题心得 - 2025 NOIP #65 - T1【构造】【神人】

题解参与者 1已保存评论 0

文章操作

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

当前评论
0 条
当前快照
1 份
快照标识符
@min51jzi
此快照首次捕获于
2025/12/01 20:41
3 个月前
此快照最后确认于
2025/12/01 20:41
3 个月前
查看原文
构造不太容易但是思路是不困难的。你发现显然是需要一次异或对齐 a,ba,b 才好修改 aa 最高位为 cc。然后不停右移异或使得 a=ca=cbb00 一次异或既可以解决,最劣情况 6464 次操作计算完成呢。
CPP
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b,c;
vector<int>op;
int ls(int x){
	for(int i=30;~i;i--)if((x>>i)&1) return i+1;
	return 0;
}
int main(){
	freopen("kks.in","r",stdin);
	freopen("kks.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin>>T;
	while(T--){
		cin>>a>>b>>c;
		if(a==b&&b==c){ cout<<"0\n\n";continue; }
		if(a==b&&b==0){ cout<<"-1\n";continue;  }
		op.clear();
		if(ls(a)<ls(b)) a^=b, op.push_back(3);
		if(ls(b)<ls(a)) b^=a, op.push_back(4);
		if(ls(c)<ls(a)){
			while(ls(b)>ls(c)){
				if(ls(b)==ls(a)) a^=b, op.push_back(3);
				op.push_back(2), b>>=1;
			}
		}
		if(ls(a)<ls(b)) a^=b, op.push_back(3);
		while(ls(c)>ls(a)){
			if(((c>>(ls(b)+ls(c)-ls(a)-1))&1)!=((a>>(ls(b)-1))&1))
				op.push_back(3), a^=b;
			op.push_back(1), a<<=1;
		}
		while(ls(b)){
			if(((c>>(ls(b)-1))&1)!=((a>>(ls(b)-1))&1))
				op.push_back(3), a^=b;
			op.push_back(2), b>>=1;
		}
		if(b!=c) b^=a,  op.push_back(4);
		cout<<op.size()<<"\n";
		for(auto i:op) cout<<i<<" ";
		cout<<"\n";
	}
	return 0;
}

评论

0 条评论,欢迎与作者交流。

正在加载评论...