用优先队列来贪心,是一个很好地想法。优先队列在很多时候可以维护最值,同时可以考虑到一些其他情况。

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

#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 99999999
#define ll __int64
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int MAXN = ;
struct node
{
int x;
int val;
}a[MAXN];
int n;
priority_queue<int, vector<int>, greater<int> >q;
bool cmp(node fa, node fb)
{
if(fa.x != fb.x)
return fa.x < fb.x;
return fa.val > fb.val;
}
int main()
{
while(cin >>n){
for(int i = ; i <= n; i++){
cin >>a[i].x >> a[i].val;
}
sort(a+, a+n+, cmp);
while(!q.empty())q.pop();
int t = ;
for(int i = ; i <= n; i++){
if(t < a[i].x){
t ++;
q.push(a[i].val);
}
else if(t == a[i].x){
int temp = q.top();
q.pop();
if(temp < a[i].val){
temp = a[i].val;
}
q.push(temp);
}
}
ll ans = ;
while(!q.empty()) {
int temp = q.top();
q.pop();
ans += temp;
}
cout<<ans<<endl;
}
}

51nod 1163贪心的更多相关文章

  1. 51nod 1163 贪心

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1163 1163 最高的奖励 基准时间限制:1 秒 空间限制:131072 ...

  2. 51nod 1163 最高的奖励(贪心+优先队列)

    题目链接:51nod 1163 最高的奖励 看着这题我立马就想到昨天也做了一道贪心加优先队列的题了奥. 按任务最晚结束时间从小到大排序,依次选择任务,如果该任务最晚结束时间比当前时间点晚,则将该任务的 ...

  3. 51nod 1163 最高的奖励

    链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1163 1163 最高的奖励  基准时间限制:1 秒 空间限制:13 ...

  4. 51nod 1625 贪心/思维

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 1625 夹克爷发红包 基准时间限制:1 秒 空间限制:13107 ...

  5. 51nod 1099 贪心/思维

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1099 1099 任务执行顺序 基准时间限制:1 秒 空间限制:13107 ...

  6. 51nod 1428 贪心

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活动安排问题 基准时间限制:1 秒 空间限制:13107 ...

  7. 51nod - 1163 巧妙的并查集 O(1)维护区间

    有N个任务,每个任务有一个最晚结束时间以及一个对应的奖励.在结束时间之前完成该任务,就可以获得对应的奖励.完成每一个任务所需的时间都是1个单位时间.有时候完成所有任务是不可能的,因为时间上可能会有冲突 ...

  8. 51nod 1672 贪心/队列

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1672 1672 区间交 基准时间限制:1 秒 空间限制:131072 K ...

  9. 51nod 1449 贪心

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1449 1449 砝码称重 题目来源: CodeForces 基准时间限制 ...

随机推荐

  1. CF 371C-Hamburgers[二分答案]

    C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. 异常总结<经典例题>

    public class Test1 { public static void main(String[] args) { try { add(1); System.out.println(" ...

  3. Code! MVC 5 App with Facebook, Twitter, LinkedIn and Google OAuth2 Sign-on (C#)

    http://www.asp.net/mvc/overview/security/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2- ...

  4. qau-国庆七天乐——B

      B - Bull Math   Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Sub ...

  5. [No000035]操作系统Operating System之OS Interface操作系统接口

    接口(Interface) 仍然从常识开始… 日常生活中有很多接口:电源插座:汽车油门… 那什么是接口? 连接两个东西.信号转换.屏蔽细节… Interface: electrical circuit ...

  6. 0e开头md5汇总

    PHP在处理哈希字符串时,会利用"!="或"=="来对哈希值进行比较,它把每一个以"0E"开头的哈希值都解释为0,所以如果两个不同的密码经过 ...

  7. java (基本语法)

    2.五大内存区 方法区就是存储共享数据的地方 3.一个实体多处引用 只有还有实体被指向,这个实体就不能消失.当所有的指向都消失之后,这个实体被视为垃圾,被垃圾回收机制不定期的回收. 堆里的实体能存储多 ...

  8. avalon.js路由

    之前自己写了一个AJAX加载页面的方法:有时候一个页面里面会分区域加载不同的东西(div,html),但是IE的回退按钮,就失去任何意义了: 这两天研究了一下avalon.js的路由: 需要准备: 1 ...

  9. js区分鼠标单双击 阻止事件冒泡

    function clickOrDblClick(obj) { count++; if (obj != undefined) { var rowStr = $.trim($(obj).find(&qu ...

  10. Codevs 1860 最大数 string大法好,STL万岁。。

    题目描述 Description 设有n个正整数(n≤20),将它们联接成一排,组成一个最大的多位整数. 输入描述 Input Description 第一行一个正整数n. 第二行n个正整数,空格隔开 ...