Duff and Weight Lifting - 587A

题目大意:某个人训练举重,他每次可以举起来2^wi的重量,不过这个人比较懒所以他想尽量减少训练的次数,如果所有的训练重量2^a1 +2^a2+....2^ak = 2^x,那么这些重量可以一次性训练(不需要连续),问他最少要训练几次才行。

分析:

已知 2^x+2^x = 2^(x+1),所以相同的是可以合并成下一个的,最后只需要判断,有多少个不能合成的即可。

代码如下:

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;

const int MAXN = 2e6+7;

int a[MAXN+1];

int main()
{
    int N, x, ans=0;

    scanf("%d", &N);

    for(int i=0; i<N; i++)
    {
        scanf("%d", &x);
        a[x] += 1;
    }

    for(int i=0; i<MAXN; i++)
    {
        a[i+1] += a[i] / 2;
        a[i] %= 2;
        ans += a[i];
    }

    printf("%d\n", ans);

    return 0;
}
时间: 2024-10-13 01:37:27

Duff and Weight Lifting - 587A的相关文章

随笔—邀请赛前训—Duff and Weight Lifting

题意:给你一串数Wi,表示一串2^Wi.规则是如果sum(2^wi)==2^x(x是整数),就可以去除这些数.否则step++: 问你最小step. 思路:考虑到2^n+2^n=2^(n+1),所以我们可以按wi从小到大将n个wi合并成n/2个(wi+1)  ,再判断n是奇偶,是奇数就step++: #include <iostream> #include <stdio.h> #include <string.h> using namespace std; const

【Henu ACM Round#14 C】Duff and Weight Lifting

[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 2^y可以由两个2^(y-1)相加得到. 则有一个贪心的策略. 就是2^x尽量都变成2^(x+1) (即能够凑就尽量凑) 如果x还有剩余的话.答案递增1 而凑上去的数字,显然是可以合并成1步操作的.因为他们的和就是2^(x+1) [代码] #include <bits/stdc++.h> #define ll long long using namespace std; const int N = 1e6; int n,a[N

Duff and Weight Lifting_贪心

Duff and Weight Lifting TimeLimit:1000MS  MemoryLimit:256MB 64-bit integer IO format:%I64d Problem Description Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of 

BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 681    Accepted Submission(s): 280 Problem Description Baby Ming is fond of weight lifting. He has a barbell pole(the

HDU 5610 Baby Ming and Weight lifting

Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1365    Accepted Submission(s): 500 Problem Description Baby Ming is fond of weight lifting. He has a barbell pole(th

HDU 5610 Baby Ming and Weight lifting 暴力

Problem Description Baby Ming is fond of weight lifting. He has a barbell pole(the weight of which can be ignored) and two different kinds of barbell disks(the weight of which are respectively a and b), the amount of each one being infinite.Baby Ming

HDU 5610 Baby Ming and Weight lifting(枚举)

Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1439    Accepted Submission(s): 525 Problem Description Baby Ming is fond of weight lifting. He has a barbell pole(t

hdu 5616

Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 178    Accepted Submission(s): 77 Problem Description Baby Ming is fond of weight lifting. He has a barbell pole(the

filter press for sale

Everybody can improve the chest muscle by lifting weights with just a little know-how. I will tell you how you can build a strong and muscular chest with only a few of the very best weight lifting exercises. The chest exercise routine goes as follows