poj supermaket (贪心)

http://poj.org/problem?id=1456

#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct nod
{
    int a;
    int  d;

};
bool cmp(nod x,nod y)
{
    return x.a>y.a;
}
int main()
{
    nod aa[10005];
    int n;
    while(cin>>n)
    {   int tt[10005]={0};
        for(int i=0;i<n;i++)
        {
        cin>>aa[i].a>>aa[i].d;
        }
        int sum=0;
        sort(aa,aa+n,cmp);
        for(int j=0;j<n;j++)
        {if(tt[aa[j].d]==0)
            {
                sum+=aa[j].a;
                tt[aa[j].d]=1;
            }
            else//////排除比利益较大但天数已经被标记的成员。
            {
                for(int i=aa[j].d;i>0;i--)
                {if(tt[i]==0)
                    {

                        sum+=aa[j].a;
                    tt[i]=1;
                    break;
                    }
                }
            }
        }
        cout<<sum<<endl;

    }
    return 0;
}
原文地址:https://www.cnblogs.com/jin-nuo/p/5536115.html