Codeforces Round #618 (Div. 1)A(观察规律)

实际上函数值为x&(-y)

答案仅和第一个数字放谁有关

 1 #define HAVE_STRUCT_TIMESPEC
 2 #include <bits/stdc++.h>
 3 using namespace std;
 4 int a[200007];
 5 int b[200007][37];
 6 int flag[67];
 7 int main(){
 8     ios::sync_with_stdio(false);
 9     cin.tie(NULL);
10     cout.tie(NULL);
11     int n;
12     cin>>n;
13     int start=1;
14     int mx=0;
15     for(int i=1;i<=n;++i){
16         cin>>a[i];
17         int temp=a[i];
18         while(temp){
19             b[i][++b[i][0]]=temp%2;//转化为二进制
20             temp>>=1;
21         }
22         for(int j=1;j<=b[i][0];++j)
23             if(b[i][j]!=0)
24                 ++flag[j];//记录有多少数字这一位上是1
25         a[n+i]=a[i];
26     }
27     for(int i=1;i<=n;++i){
28         int he=0;
29         for(int j=1;j<=b[i][0];++j)
30             if(b[i][j]&&flag[j]==1)//如果仅有a[i]这一位上为1,那么它放在顺序的第一个时可以为总和做出1<<(j-1)的贡献
31                 he|=(1ll<<(j-1));
32         if(he>mx){//更新最大值
33             mx=he;
34             start=i;
35         }
36     }
37     for(int i=start;i<=n-1+start;++i)
38         cout<<a[i]<<" ";
39     return 0;
40 }

猜你喜欢

转载自www.cnblogs.com/ldudxy/p/12292719.html
今日推荐