我用char型开了一亿的数组过了!!!哈哈哈哈!!!

#include<iostream>
using namespace std;
char c[100000000+10]={};
long long t=0;
int main()
{
int i,j,n,temp,maxv=0,minv;
cin>>n;
for(i=0;i<n;++i)
{
cin>>temp;
c[temp]++;
if(temp>maxv)
maxv=temp;
}
for(i=0;i<=maxv;++i)
{
/*for(j=0;j<=maxv;++j)
cout<<c[j]<<' ';
cout<<endl;*/
if(c[i]>0)
{
c[i]--;
for(j=i;j<=maxv;++j)
{
if(c[j]>0)
{
c[j]--;
c[i+j]++;
if(i+j>maxv) maxv=i+j;
t+=i+j;
break;
}
}
}
if(c[i]>0)
i--;
}
cout<<t<<endl;
return 0;
}

8 条评论

  • @ 2018-03-27 17:15:09

    优先队列

  • @ 2016-05-12 20:34:41

    哪错了

  • @ 2016-05-12 20:34:21
    #include<cstdio>
    #include<iostream>
    using namespace std;
    int h,t,n;
    long long int A[25000],ans;
    void maopao(int l,int r)
    {
        for(int i=l;i<r;i++)
        {
            for(int j=r;j>i;j--)
            {
                if(A[j]<A[j-1])
                {
                    long long int tp=A[j];A[j]=A[j-1];A[j-1]=tp;
                }
            }
        }
    }
    int main()
    {
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>A[i];
        }
        h=1;t=n;
        while(h<t)
        {
            t++;
            A[t]=A[h]+A[h+1];
            ans+=A[t];
            h+=2;
            for(int j=t;j>h && A[j]<A[j-1];j--)
            {
                long long int tp=A[j];A[j]=A[j-1];A[j-1]=tp;
            }   
        }   
        cout<<ans;
        return 0;
    }
    
  • @ 2014-10-30 22:03:02

    用优先队列直接过

    #include<iostream>
    #include<queue>
    using namespace std;
    priority_queue<int> s;
    int main()
    {
    int n,a,ans=0,t=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
    cin>>a;
    s.push(-a);
    }
    while(!s.empty())
    {
    if(t!=0)s.push(t);
    t=0;
    t+=s.top();
    s.pop();
    t+=s.top();
    s.pop();
    ans-=t;
    }
    cout<<ans<<endl;
    return 0;
    }

  • @ 2014-10-25 16:24:13

    LZ写麻烦了
    #include<cstdio>
    char a[100000000]={0};int b[2]={0};
    int main()
    {
    int n,tmp,ok=0,ans=0;scanf("%d",&n);
    for(int i=0;i<n;i++){scanf("%d",&tmp);a[tmp]++;}
    for(int i=0;i<100000000;i++)
    {
    while(a[i]--)
    {
    b[ok++]=i;
    if(ok==2)
    {
    ok=0;ans+=b[0]+b[1];
    a[b[0]+b[1]]++;
    }
    }
    }
    printf("%d",ans);
    return 0;
    }

  • @ 2014-08-15 08:46:46

    一亿。。。

  • @ 2014-01-27 00:52:42

    你没有考虑有两堆果子质量相同的情况诶

  • @ 2013-08-23 12:32:46

    有非常厉害的基数排序也很好过

  • 1

信息

ID
1097
难度
6
分类
贪心 点击显示
标签
递交数
23854
已通过
6310
通过率
26%
被复制
41
上传者