标签:turn for eof name 题意 pre push size oid
题意:一个数组,重新打乱后前缀异或和递增。问这样的排列。
将所有元素按照二进制最高位分组。每次选当前前缀和sum的二进制最低的0位,再从分组中挑一个作为答案。先放首1在较低位的再放首1在较高位的总是可行的。首1都在同一位的先放哪个都是一样的。
//#pragma comment(linker,"/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<cmath> #include<queue> #include<stack> #include<map> #include<set> #include<algorithm> #include <stack> #include <bitset> using namespace std; const int SZ=100010,INF=0x7FFFFFFF; typedef long long lon; lon n,arr[SZ],ans[SZ]; vector<lon> vct[70]; lon one=1; void init() { cin>>n; for(lon i=0;i<n;++i) { cin>>arr[i]; for(lon j=62;j>=0;--j) { if(arr[i]&(one<<j)) { vct[j].push_back(arr[i]); break; } } } } bool work() { lon cur=0; for(lon i=0;i<n;++i) { bool ok=0; for(lon j=0;j<62;++j) { if((cur&(one<<j))==0&&vct[j].size()) { cur^=(ans[i]=vct[j].back()); vct[j].pop_back(); ok=1; break; } } if(!ok)return 0; } return 1; } int main() { std::ios::sync_with_stdio(0); //freopen("d:\\1.txt","r",stdin); //for(;scanf("%d",&n)!=EOF;) { init(); if(!work())cout<<"No"<<endl; else { cout<<"Yes"<<endl; for(lon i=0;i<n;++i) { if(i)cout<<" "; cout<<ans[i]; }cout<<endl; } } return 0; }
codeforces 966c//Big Secret// Codeforces Round #477 (Div. 1)
标签:turn for eof name 题意 pre push size oid
原文地址:https://www.cnblogs.com/gaudar/p/9715299.html