每次写poj的题都很崩溃,貌似从来没有一次一发就ac的,每次都有特别多的细节需要考虑。还有就是自己写的太粗糙了,应该把每种情况都想到的,总是急着交,然后刷一页wa。

优先队列直接用stl就可以,简单实用。

 #include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
using namespace std;
const double Pi=3.14159265358979323846;
typedef long long ll;
const int MAXN=+;
const int dx[]={,,,,-};
const int dy[]={,-,,,};
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll mod=1e9+;
struct node{
int p,d;
}a[MAXN];
bool cmp(node a,node b)
{
return a.d>b.d;
}
int main()
{
int n;scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d",&a[i].d,&a[i].p);
}
int L,P;
scanf("%d%d",&L,&P);
for(int i=;i<=n;i++)
{
a[i].d=L-a[i].d;
}
sort(a+,a+n+,cmp);
/*for(int i=1;i<=n;i++)
{
cout <<a[i].d<<endl;
}*/
int ans=;
priority_queue <int> pque;
if(n==&&P-L<)
{
puts("-1");
return ;
}
for(int i=n;i>=;i--)
{
int dis=a[i].d-a[i+].d; if(dis>P)
{
while(dis>P&&!pque.empty())
{
P+=pque.top();
pque.pop();
ans++;
}
if(dis>P)
{
puts("-1");
return ;
}else
{
P=P-dis;
}
} else
{
P=P-dis;
}
pque.push(a[i].p);
}
int l=L-a[].d;
while(!pque.empty()&&P<l)
{
P+=pque.top();
ans++;
pque.pop();
}
if(P<l) puts("-1");
else printf("%d\n",ans);
return ;
}

优先队列(挑程)poj 2431的更多相关文章

  1. POJ 2431 优先队列

    汽车每过一单位消耗一单位油,其中有给定加油站可加油,问到达终点加油的最小次数. 做法很多的题,其中优先对列解这题是很经典的想法,枚举每个加油站,判断下当前油量是否小于0,小于0就在前面挑最大几个直至油 ...

  2. POJ 2431 Expedition (贪心+优先队列)

    题目地址:POJ 2431 将路过的加油站的加油量放到一个优先队列里,每次当油量不够时,就一直加队列里油量最大的直到能够到达下一站为止. 代码例如以下: #include <iostream&g ...

  3. poj 2431 【优先队列】

    poj 2431 Description A group of cows grabbed a truck and ventured on an expedition deep into the jun ...

  4. POJ 2431 Expedition(探险)

    POJ 2431 Expedition(探险) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of co ...

  5. poj - 2431 Expedition (优先队列)

    http://poj.org/problem?id=2431 你需要驾驶一辆卡车做一次长途旅行,但是卡车每走一单位就会消耗掉一单位的油,如果没有油就走不了,为了修复卡车,卡车需要被开到距离最近的城镇, ...

  6. POJ 2431 Expedition (贪心 + 优先队列)

    题目链接:http://poj.org/problem?id=2431 题意:一辆卡车要行驶L单位距离,卡车上有P单位的汽油.一共有N个加油站,分别给出加油站距终点距离,及加油站可以加的油量.问卡车能 ...

  7. POJ 2431——Expedition(贪心,优先队列)

    链接:http://poj.org/problem?id=2431 题解 #include<iostream> #include<algorithm> #include< ...

  8. poj 2431 Expedition 贪心 优先队列 题解《挑战程序设计竞赛》

    地址 http://poj.org/problem?id=2431 题解 朴素想法就是dfs 经过该点的时候决定是否加油 中间加了一点剪枝 如果加油次数已经比已知最少的加油次数要大或者等于了 那么就剪 ...

  9. poj 2431 Expedition 贪心+优先队列 很好很好的一道题!!!

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10025   Accepted: 2918 Descr ...

随机推荐

  1. FileZilla Server隐藏版本号教程

    1.查看当前是否泄漏版本号 telnet FileZilla监听端口查看返回信息:telnet 192.168.220.130 21 2.自定义欢迎信息 登录FileZilla--点击“Edit”-- ...

  2. 搜索路径---PYTHONPATH 变量

  3. 在用mybatis向MySQL数据库中插入时间时报错:Incorrect datetime value: '' for column '' at row 1

    问题说明:使用的MySQL是5.1.37版本,用的mysql-connector-java-5.0.4.jar版本,在java文件中定义的字段是Date类型,MySQL中定义的字段类型是datetim ...

  4. lda topic number

    Hi Vikas -- the optimum number of topics (K in LDA) is dependent on a at least two factors: Firstly, ...

  5. HDU 1005 Number Sequence(数论)

    HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...

  6. windows 常用dos命令

    explorer目录 打开当前目录 explorer . 打开上级目录 explorer .. 打开任意目录 explorer dirname cls 命令 清屏屏幕,屏幕显示的所有字符信息都是存放在 ...

  7. Resharper插件的使用

    一.Resharper设置 1.1 智能提示 安装完毕后,IDE 的智能提示(Intellisense)便会默认使用 Resharper 的提示,不知道为什么,我一直不太喜欢它的提示.改过来,是在Op ...

  8. IIS设置上传文件大小限制

    单位为字节. 500*1024*1024=524288000

  9. sas 选择一段日期,和一定周期,生成日期序列和周期序列

    工作需要,得选择一段日期,和一定周期,生成日期序列和周期序列.暂时用七天为一个周期 data d; format date date9.; do date='04mar2018'd to'05may2 ...

  10. Spring MVC中注解: @ModelAttribute 与@RequestParam区别

    相关链接 : https://blog.csdn.net/huang343/article/details/77491096