2019 G 二进制的关系

 

G  

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e5 + 10;
int n ;
int a[maxn];
signed main(){
    ios::sync_with_stdio(0);
    cin >> n;
    int j = 1;//记录当前层
    for(int i = 1; i<=n; i++){
        int temp;
        cin >> temp;
        if(i >= (1<<j)) j++;//利用二进制控制层数
        a[j]+=temp;
    }
    int maxx = a[1];
    int t = 1;
    for(int i = 2; i <= j; i++){
        if(a[i] > maxx) {
            maxx = a[i];
            t = i;
        }
    }
    cout << t << endl;
    return 0;
}
View Code

 

https://blog.csdn.net/qq_40727168/article/details/103112319?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-8&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-8

posted @ 2020-04-13 17:17  Hazelxcf  阅读(241)  评论(0)    收藏  举报