8.10模拟赛总结
T1
题面
::::info[观察]
在一个合法的做法中,一根彩带连结的节点之和必然为奇数,且对于
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
x=x*10+ch-'0',ch=getchar();
return x*f;
}
void write(int x)
{
if(x<0)
putchar('-'),x=-x;
if(x>9)
write(x/10);
putchar(x%10+'0');
return;
}
struct node{
ll a,b;
};
node c[100005];
ll n;
ll p[200030];
map<ll,ll> pos;
map<ll,bool> flag1;
ll match(ll x,ll best,ll two){
return (best+two-x)%two;
}
int main(){
freopen("popipa.in","r",stdin);
freopen("popipa.out","w",stdout);
cin>>n;
memset(p,0,sizeof(p));
for(int i=0;i<n;i++){
cin>>c[i].a>>c[i].b;
pos[c[i].a]=i;
pos[c[i].b]=i;
}
ll two=n*2;
for(int i=0;i<n;i++){
ll num=(c[i].a+c[i].b)%two;
if(num%2==1){
p[num]++;
}
}
ll tar=1;
ll maxcnt=0;
for(ll x=1;x<two;x+=2){
if(p[x]>maxcnt){
maxcnt=p[x];
tar=x;
}
}
ll k=0;
for(int i=0;i<n;i++){
ll modv=(c[i].a+c[i].b)%two;
if(modv%2==1&&modv==tar){
flag1[i]=true;
}else{
flag1[i]=false;
k++;
}
}
cout<<k<<endl;
for(int i=0;i<n;i++){
if(!flag1[i]){
ll s=i;
ll o=0;
while(true){
ll u;
if(o==0) u=c[s].a;
else u=c[s].b;
ll v=match(u,tar,two);
ll s2=-1;
if(pos.count(v)) s2=pos[v];
ll ode;
if(o==0) ode=c[s].b;
else ode=c[s].a;
cout<<s<<" "<<ode<<" "<<v<<endl;
flag1[s]=true;
pos[v]=s;
pos[ode]=-1;
if(s2==-1) break;
s=s2;
if(c[s].a==v) o=1;
else if(c[s].b==v) o=0;
}
}
}
return 0;
fclose(stdin);
fclose(stdout);
}
::::
T2
::::info[未作出原因]
并没有贪心地去拆位计算
::::
::::info[做法]
由于
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
x=x*10+ch-'0',ch=getchar();
return x*f;
}
void write(int x)
{
if(x<0)
putchar('-'),x=-x;
if(x>9)
write(x/10);
putchar(x%10+'0');
return;
}
ll t,n;
void solve(){
cin>>n;
vector<ll> v,tmp;
for(int i=1;i<=n;++i){
ll x;
cin>>x;
v.push_back(x);
}
ll ans=0;
for(int i=30;i>=0;--i){
if(v.size()==2){
break;
}
ll now=0;
for(int j=0;j<v.size();++j){
ll x=v[j];
if((x>>i)&1){
now|=x;
}
else{
tmp.push_back(x);
}
}
if(!now||!tmp.size()){
tmp.clear();
continue;
}
v=tmp;
tmp.clear();
v.push_back(now);
}
ll now=0;
for(int i=1;i<v.size();++i){
now|=v[i];
}
cout<<(v[0]^now)<<'\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--){
solve();
}
}
::::