poj1456(贪心+优先队列)

题意:给定一个物品的价值pi和他的截止时间di,只有在截止时间卖出才能得到pi价值,一天只能卖一个

这个其实可以这样想。。前几天能卖多少卖多少,可是这时候就考虑到后面有些价值比较大的东西没地方卖要放到前面来卖。。这样的话其实可以在前面找个最小值,然后用当前价值比较大的物品去代替前面卖的物品就行了。。

 

 

 

/**
 *        ┏┓    ┏┓
 *        ┏┛┗━━━━━━━┛┗━━━┓
 *        ┃       ┃  
 *        ┃   ━    ┃
 *        ┃ >   < ┃
 *        ┃       ┃
 *        ┃... ⌒ ...  ┃
 *        ┃       ┃
 *        ┗━┓   ┏━┛
 *          ┃   ┃ Code is far away from bug with the animal protecting          
 *          ┃   ┃   神兽保佑,代码无bug
 *          ┃   ┃           
 *          ┃   ┃        
 *          ┃   ┃
 *          ┃   ┃           
 *          ┃   ┗━━━┓
 *          ┃       ┣┓
 *          ┃       ┏┛
 *          ┗┓┓┏━┳┓┏┛
 *           ┃┫┫ ┃┫┫
 *           ┗┻┛ ┗┻┛
 */
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1LL<<(x))
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid ((x+y)/2)
#define NM 100005
#define nm 2005
#define pi 3.1415926535897931
const int inf=1e9+7;
using namespace std;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}







struct tmp{
    int x,y;
    bool operator<(const tmp&o)const{return y<o.y||(y==o.y&&x>o.x);}
}a[NM];
int n;
priority_queue<tmp,vector<int>,greater<int> >q;
int ans;


int main(){
    while(~scanf("%d",&n)){
	inc(i,1,n)a[i].x=read(),a[i].y=read();
	sort(a+1,a+1+n);
	inc(i,1,n)if(a[i].y>q.size())q.push(a[i].x);
	else if(q.top()<a[i].x)q.pop(),q.push(a[i].x);
	for(ans=0;!q.empty();q.pop())ans+=q.top();
	printf("%d\n",ans);
    }
    return 0;
}

 

 

 

/**
 * ┏┓ ┏┓
 * ┏┛┗━━━━━━━┛┗━━━┓
 * ┃ ┃
 * ┃ ━ ┃
 * ┃ > < ┃
 * ┃ ┃
 * ┃... ⌒ ... ┃
 * ┃ ┃
 * ┗━┓ ┏━┛
 * ┃ ┃ Code is far away from bug with the animal protecting
 * ┃ ┃   神兽保佑,代码无bug
 * ┃ ┃
 * ┃ ┃ 
 * ┃ ┃
 * ┃ ┃
 * ┃ ┗━━━┓
 * ┃ ┣┓
 * ┃ ┏┛
 * ┗┓┓┏━┳┓┏┛
 * ┃┫┫ ┃┫┫
 * ┗┻┛ ┗┻┛
 */
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1LL<<(x))
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid ((x+y)/2)
#define NM 100005
#define nm 2005
#define pi 3.1415926535897931
const int inf=1e9+7;
using namespace std;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}

 

 

 

struct tmp{
    int x,y;
    bool operator<(const tmp&o)const{return y<o.y||(y==o.y&&x>o.x);}
}a[NM];
int n;
priority_queue<tmp,vector<int>,greater<int> >q;
int ans;


int main(){
    while(~scanf("%d",&n)){
    inc(i,1,n)a[i].x=read(),a[i].y=read();
    sort(a+1,a+1+n);
    inc(i,1,n)if(a[i].y>q.size())q.push(a[i].x);
    else if(q.top()<a[i].x)q.pop(),q.push(a[i].x);
    for(ans=0;!q.empty();q.pop())ans+=q.top();
    printf("%d\n",ans);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值