Codeforces Round #140 (Div. 1) Naughty Stone Piles 贪心
2015-04-16 22:22
246 查看
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 1000010;
__int64 sum[maxn] ;
__int64 num[maxn];
__int64 ans[maxn];
__int64 vis[maxn] ;
__int64 query;
__int64 n , q;
bool cmp1(__int64 a ,__int64 b)
{
return a > b;
}
int main()
{
while(~scanf("%I64d" ,&n))
{
for(int i = 1;i <= n;i++)
scanf("%I64d",&num[i]) ;
sort(num+1 , num+1+n , cmp1);
sum[0] = 0;
for(int i = 1;i <= n ;i++)
sum[i] = sum[i-1] + num[i];
memset(ans , 0 ,sizeof(ans)) ;
for(int k = 1;k < maxn; k++)
{
__int64 pos_s = 0 ;
__int64 pos_e = 1;
__int64 t = 0;
__int64 len = (__int64)k;
while(pos_s < n)
{
if(pos_e > n) pos_e = n;
ans[k] += (sum[pos_e] - sum[pos_s])*t ;
t++ ;
pos_s = pos_e;
pos_e += len;
len *= (__int64)k;
}
}
scanf("%I64d" , &q);
for(int i = 1;i <= q;i++)
{
scanf("%I64d" ,&query) ;
if(query > n) query = (__int64)n ;
printf("%I64d%c" ,ans[query] ,i == q?'\n':' ');
}
}
return 0;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 1000010;
__int64 sum[maxn] ;
__int64 num[maxn];
__int64 ans[maxn];
__int64 vis[maxn] ;
__int64 query;
__int64 n , q;
bool cmp1(__int64 a ,__int64 b)
{
return a > b;
}
int main()
{
while(~scanf("%I64d" ,&n))
{
for(int i = 1;i <= n;i++)
scanf("%I64d",&num[i]) ;
sort(num+1 , num+1+n , cmp1);
sum[0] = 0;
for(int i = 1;i <= n ;i++)
sum[i] = sum[i-1] + num[i];
memset(ans , 0 ,sizeof(ans)) ;
for(int k = 1;k < maxn; k++)
{
__int64 pos_s = 0 ;
__int64 pos_e = 1;
__int64 t = 0;
__int64 len = (__int64)k;
while(pos_s < n)
{
if(pos_e > n) pos_e = n;
ans[k] += (sum[pos_e] - sum[pos_s])*t ;
t++ ;
pos_s = pos_e;
pos_e += len;
len *= (__int64)k;
}
}
scanf("%I64d" , &q);
for(int i = 1;i <= q;i++)
{
scanf("%I64d" ,&query) ;
if(query > n) query = (__int64)n ;
printf("%I64d%c" ,ans[query] ,i == q?'\n':' ');
}
}
return 0;
}
相关文章推荐
- 【贪心】CodeForces Round #140(226B) - Naughty Stone Piles
- Codeforces Round #140 (Div. 1) B Naughty Stone Piles
- CodeForces Round #140(226B) - Naughty Stone Piles
- Codeforces Round #140 (Div. 1)D The table 贪心
- 【Codeforces Round 326 (Div 2)A】【贪心】Duff and Meat 屯肉前溯花费最低
- Codeforces Round #437 (Div. 2 C. Ordering Pizza 贪心 only two types of pizza
- CodeForces Round #202 (Div. 2) / ProblemSet 349B - B. Color the Fence 【贪心】
- Codeforces Round #342 (Div. 2) B. War of the Corporations 贪心
- 【Codeforces Round 354 (Div 2)A】【水题 贪心】Nicholas and Permutation 恰好交换一次的pos[n]-pos[1]
- Codeforces Round #461 (Div. 2) D. Robot Vacuum Cleaner(贪心)
- 【Codeforces Round 335 (Div 2) C】【贪心 脑洞 有趣排序】Sorting Railway Cars 全排列排序可以提前后提后的最小操作数
- 【Codeforces Round 263 (Div 2)B】【水题 贪心】Appleman and Card Game 选字符,每个字符个数的平方
- 【Codeforces Round 336 (Div 2) A】【贪心 水题】Saitama Destroys Hotel 电梯只下不上 接n人到达0层最早时刻
- Codeforces Round #169 (Div. 2) D. Little Girl and Maximum XOR(贪心,中等)
- Codeforces Round #277.5 (Div. 2)C. Given Length and Sum of Digits...(贪心)
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心
- Codeforces Round #FF (Div. 1)——A贪心——DZY Loves Sequences
- codeforces round 345 div2 Image Interview 贪心 + 二分
- Codeforces Round #FF (Div. 2) D. DZY Loves Modification 贪心+优先队列
- Codeforces Round #415 (Div. 2)(A,暴力,B,贪心,排序)