每次写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. python 数字格式化

    第二种办法比较常用:   %02d print '%02d' % 11

  2. html 打电话 发短信

    打电话:window.location.href = 'tel:'+tel 发短信:window.location.href = 'sms:'+tel

  3. js如何返回两个数的商的整数和余数部分?

    js中,如何返回两个数的商的整数和余数部分? 如: num1:100 ,num2:12 var num = parseFloat(100/12); //值: 8.333333333333334 那么如 ...

  4. HTTP、TCP、UDP的区别

    TCP.UDP的区别 1.TCP面向连接(如打电话要先拨号建立连接);UDP是无连接的,即发送数据之前不需要建立连接 2.TCP提供可靠的服务.也就是说,通过TCP连接传送的数据,无差错,不丢失,不重 ...

  5. RBAC功能模块

  6. GDI中StretchBlt或Blt缩放图片失真问题

    在用Scrollview控件的缩放图片时,严重失真: 解决方法:dc.SetStretchBltMode(COLORONCOLOR). 参考文章:https://blog.csdn.net/m3728 ...

  7. Html.DropDownList()的用法

    页面代码如下: <%= Html.DropDownList("Category", ViewData["Categories"] as SelectLis ...

  8. TensorFlow函数:tf.lin_space

    函数:tf.lin_space 别名: tf.lin_space tf.linspace lin_space( start, stop, num, name=None ) 参见指南:生成常量,序列和随 ...

  9. Oracle使用exp和imp导出、导入数据

    ===========导出============ exp 用户名/密码@服务器(localhost) file=文件路径.dmp owner=(用户名) ===========导入========= ...

  10. Python 数据处理库 pandas 入门教程

    Python 数据处理库 pandas 入门教程2018/04/17 · 工具与框架 · Pandas, Python 原文出处: 强波的技术博客 pandas是一个Python语言的软件包,在我们使 ...