51nod 1163贪心
用优先队列来贪心,是一个很好地想法。优先队列在很多时候可以维护最值,同时可以考虑到一些其他情况。
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贪心的更多相关文章
- 51nod 1163 贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1163 1163 最高的奖励 基准时间限制:1 秒 空间限制:131072 ...
- 51nod 1163 最高的奖励(贪心+优先队列)
题目链接:51nod 1163 最高的奖励 看着这题我立马就想到昨天也做了一道贪心加优先队列的题了奥. 按任务最晚结束时间从小到大排序,依次选择任务,如果该任务最晚结束时间比当前时间点晚,则将该任务的 ...
- 51nod 1163 最高的奖励
链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1163 1163 最高的奖励 基准时间限制:1 秒 空间限制:13 ...
- 51nod 1625 贪心/思维
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 1625 夹克爷发红包 基准时间限制:1 秒 空间限制:13107 ...
- 51nod 1099 贪心/思维
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1099 1099 任务执行顺序 基准时间限制:1 秒 空间限制:13107 ...
- 51nod 1428 贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活动安排问题 基准时间限制:1 秒 空间限制:13107 ...
- 51nod - 1163 巧妙的并查集 O(1)维护区间
有N个任务,每个任务有一个最晚结束时间以及一个对应的奖励.在结束时间之前完成该任务,就可以获得对应的奖励.完成每一个任务所需的时间都是1个单位时间.有时候完成所有任务是不可能的,因为时间上可能会有冲突 ...
- 51nod 1672 贪心/队列
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1672 1672 区间交 基准时间限制:1 秒 空间限制:131072 K ...
- 51nod 1449 贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1449 1449 砝码称重 题目来源: CodeForces 基准时间限制 ...
随机推荐
- Miller-Rabin素数快速检测
满足费马小定理 a^(n-1) === 1(mod n) --->伪素数 对于所有a belong Zn*,总存在满足的合数n,称为Carmichael数 ------------- ...
- Unity3D所使用的第三方工具
前言 最近在研究Unity3D的结构和原理.关于Unity3D怎么用之类的教程在网上一找一大堆,想看教程之类的就不用看这篇文章了.我想做的是从使用Unity3D所看到的表象(表),摸透其设计原则和组织 ...
- BZOJ 1208: [HNOI2004]宠物收养所
1208: [HNOI2004]宠物收养所 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 7514 Solved: 2982[Submit][Sta ...
- Net中HttpClient 重试
/// <summary> /// 重试 /// </summary> public class RetryHandler : ...
- varnish 的一个配置
backend default { .host = "10.32.26.31"; .port = "; } sub vcl_recv { if (req.url ~ &q ...
- ACA烤箱菜单各项温度
说明书找不到了, 网上找到的各项温度说明, 记一个备用 casserole 218度 cake 171度 backery 177度 frozen food 238度 patato 232度 roast ...
- Oracle中使用Entity Framework 6.x Code-First方式开发
去年写过一篇EF的简单学习笔记,当时EF还不支持Oracle的Code-First开发模式,今天无意又看了下Oracle官网,发现EF6.X已经支持了,并且给出了二篇教程(英文版): 1.Using ...
- 小记sql server临时表与表变量的区别
临时表与表变量都可以起到“临时”的作用,那么两者主要的区别是什么呢? 这里不讨论创建方式,以及全局临时表.会话临时表这些,主要记录一下个人对两者的主要区别以及适用情况的看法,有什么不对或补充的地方,欢 ...
- PHP学习资料分享
PHP有着开源.执行效率高.优化代码运行等特性,功能强大,被广泛运用,很多大型企业网站开发的首选,百度.腾讯.新浪.金山等均采用了PHP开发.学好PHP对网络开发人员而言具有很好的发展前景,市场对PH ...
- win8/8.1 免密码登录设置
http://www.ehow.com/how_8013338_start-windows-password.html 原文见上方链接 1,win+r调出命令输入窗口,输入 netplwiz 回车 2 ...