51nod 1596 搬货物

来源:互联网 发布:淘宝直播公司 编辑:程序博客网 时间:2024/05/20 06:09

题目链接:

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1596

题解:

论外挂的重要性,强行卡过去。

代码:

#include <map>#include <cmath>#include <vector>#include <queue>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define met(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3fconst int maxn = 1e6+10;vector<int> p1,p2;priority_queue<int,vector<int>,greater<int> >q;map<int,int> mp;int num[maxn];void init(){    mp.clear();    while(!q.empty())        q.pop();}template <class T>inline void scan_d(T &ret){    char c;    ret = 0;    while ((c = getchar()) < '0' || c > '9');    while (c >= '0' && c <= '9')    {        ret = ret * 10 + (c - '0'), c = getchar();    }}int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        init();        int x;        for(int i=0;i<n;i++)        {            scan_d(x);            if(!mp[x])                q.push(x);            mp[x]++;        }        int cnt=0;        while(!q.empty())        {            int w=q.top();            q.pop();            int x=mp[w];            int y=x/2;            int z=x%2;            if(y)            {                if(!mp[w+1])                    q.push(w+1);                mp[w+1]+=y;            }            if(z)                cnt++;        }        printf("%d\n",cnt);    }}
原创粉丝点击