poj supermaket (贪心)

简介: http://poj.org/problem?id=1456 #include #include #include using namespace std; struct nod { int a; int d; }; bool cmp(nod x,nod y) { return x.

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;
}

 

相关文章
|
9月前
poj 1185 炮兵阵地 (状态压缩dp)
如果你是刚刚开始做状态压缩dp,我建议你先看看 poj 3254 Corn Fields 这是一道比这一题更简单,更容易入门的题目。 还有在代码中我用了一个很巧妙的方法求一个数二进制数中1的个数 具体请看我博客中 x& (x - 1)==0 这篇文章 链接 。
23 1
|
9月前
poj 1990 MooFest 树状数组
题意就是有N头牛,每头牛都有一个坐标和声调值(x, v),两头牛之间通讯要花费的能量是他们的距离乘以最大的一个音调值,现在要任意两头牛之间都相互通讯一次,求总共需要花费多少能量?
26 0
HDU7018.Banzhuan(计算几何+贪心)
HDU7018.Banzhuan(计算几何+贪心)
88 0
HDU7018.Banzhuan(计算几何+贪心)
|
人工智能
POJ 2370 Democracy in danger(简单贪心)
Democracy in danger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3388   Accepted: 2508 Description In one of the...
941 0
|
文件存储
poj 2229 Sumsets 【动态规划】
点击打开题目 Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 13291   Accepted: 5324 Description Far...
911 0
|
机器学习/深度学习
【OJ】贪心法 Saruman&#39;s Army POJ 3069 /acmclub 12132
题目链接:点击打开链接 /* 6 10 贪心法Saruman's Army POJ 3069 1 7 15 20 30 50 ans=3 */ #include #include using namespace std; int x[1010]; int main(){ // freopen("贪心法 Saruman's Army poj3069.
830 0
|
机器学习/深度学习
【OJ】贪心法 Saruman's Army POJ 3069 /acmclub 12132
题目链接:点击打开链接 /* 6 10 贪心法Saruman's Army POJ 3069 1 7 15 20 30 50 ans=3 */ #include #include using namespace std; int x[1010]; ...
869 0