现在的位置: 首页 > 综合 > 正文

7.16C

2013年07月16日 ⁄ 综合 ⁄ 共 469字 ⁄ 字号 评论关闭

题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26304#problem/C
这题实际上就是先从大到小排序,每次对前4^i 个数求和,i from 0 to n,再求总和,意思弄懂就很水了

#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
long long arr[2000001];
 
bool cmp(int a, int b) {
    return a > b;
}
int main() {
    freopen("7.16C.txt", "r", stdin);
    int N;
    while(scanf("%d", &N) != EOF) {
        for(int i = 0; i < N; ++ i) {
            scanf("%I64d", &arr[i]);
        }
        sort(arr, arr + N, cmp);
        long long sum = 0;
        int total = N;
        while(total) {
            for(int i = 0; i < total; ++ i) {
                sum += arr[i];
            }
            total /= 4;
        }
        printf("%I64d\n", sum);
    }
    return 0;
}

抱歉!评论已关闭.