不懂就问
查看原帖
不懂就问
705623
wantongxue楼主2025/1/27 23:51

rt

为啥加个括号就A了

AC代码

#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,ans,k,tot,cnt;
int a[500010];
bool f=false;

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		ans^=a[i];
	}
	if(ans==0){
		cout<<"lose";
		return 0;
	}
	int t=ans;
	while(t!=0){
		++tot;
		if(t|1==t) k=tot;
		t>>=1;
	}
	for(int i=1;i<=n;i++){
		int s;
		t=a[i];tot=0;
		while(t!=0){
			++tot;
			if((t|1)==t) s=tot;//在这里
//			cout<<(t|1)<<" "<<t<<endl;
			t>>=1;
			if(s==k) f=true;
		}
		if(f){
			cnt=i;
			break;
		}
	}
	cout<<a[cnt]-(ans^a[cnt])<<" "<<cnt<<endl;
	for(int i=1;i<=n;i++){
		if(i==cnt) cout<<(ans^a[cnt]);
		else cout<<a[i];
		cout<<" ";
	}
	return 0;
}

WA on#4

#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,ans,k,tot,cnt;
int a[500010];
bool f=false;

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		ans^=a[i];
	}
	if(ans==0){
		cout<<"lose";
		return 0;
	}
	int t=ans;
	while(t!=0){
		++tot;
		if(t|1==t) k=tot;
		t>>=1;
	}
	for(int i=1;i<=n;i++){
		int s;
		t=a[i];tot=0;
		while(t!=0){
			++tot;
			if(t|1==t) s=tot;//在这里
//			cout<<(t|1)<<" "<<t<<endl;
			t>>=1;
			if(s==k) f=true;
		}
		if(f){
			cnt=i;
			break;
		}
	}
	cout<<a[cnt]-(ans^a[cnt])<<" "<<cnt<<endl;
	for(int i=1;i<=n;i++){
		if(i==cnt) cout<<(ans^a[cnt]);
		else cout<<a[i];
		cout<<" ";
	}
	return 0;
}
2025/1/27 23:51
加载中...