刷题——Expedition POJ
来源:互联网 发布:java system.gc 编辑:程序博客网 时间:2024/06/08 20:14
/*
一辆车子要去往L远的镇上,有P容量的油,没走1单位消耗一单位的油
路上有n个加油站
给你加油站离镇的距离和加油站的油量
求最小加油次数到镇上
到不了则输出-1
*/
#include <stdio.h>
#include <queue>
using namespace std;
struct node
{
friend bool operator< (node n1, node n2)
{
return n1.jl<n2.jl;
}
int qy;
int jl;
};
priority_queue<node>que;
priority_queue<int>q;
int main(){
int n,l,p;
while(~scanf("%d",&n)){
while(!que.empty())que.pop();
while(!q.empty())q.pop();
for(int i=0;i<n;i++){
int jl,qy;
scanf("%d %d",&jl,&qy);
que.push(node{qy,jl});
}
scanf("%d %d",&l,&p);
int ks=p,num=0;
while(ks<l){
if(!q.empty()){
p+=q.top();
ks+=q.top();
q.pop();
num++;
}
while(!que.empty()&&(l-que.top().jl)<=p){
q.push(que.top().qy);
que.pop();
}
if(ks<l&&q.empty())break;
}
if(ks<l)printf("-1\n");
else printf("%d\n",num);
}
return 0;
}
一辆车子要去往L远的镇上,有P容量的油,没走1单位消耗一单位的油
路上有n个加油站
给你加油站离镇的距离和加油站的油量
求最小加油次数到镇上
到不了则输出-1
*/
#include <stdio.h>
#include <queue>
using namespace std;
struct node
{
friend bool operator< (node n1, node n2)
{
return n1.jl<n2.jl;
}
int qy;
int jl;
};
priority_queue<node>que;
priority_queue<int>q;
int main(){
int n,l,p;
while(~scanf("%d",&n)){
while(!que.empty())que.pop();
while(!q.empty())q.pop();
for(int i=0;i<n;i++){
int jl,qy;
scanf("%d %d",&jl,&qy);
que.push(node{qy,jl});
}
scanf("%d %d",&l,&p);
int ks=p,num=0;
while(ks<l){
if(!q.empty()){
p+=q.top();
ks+=q.top();
q.pop();
num++;
}
while(!que.empty()&&(l-que.top().jl)<=p){
q.push(que.top().qy);
que.pop();
}
if(ks<l&&q.empty())break;
}
if(ks<l)printf("-1\n");
else printf("%d\n",num);
}
return 0;
}
阅读全文
0 0
- 刷题——Expedition POJ
- Poj—2431 Expedition 优先队列使用经典例题
- Expedition POJ
- poj 2431 Expedition 贪心
- poj 2431 Expedition
- poj 2431 Expedition
- POJ-2431-Expedition
- poj 2431 Expedition
- POJ 2431 Expedition
- POJ 2431 Expedition(树)
- POJ 2431 Expedition
- poj 2431 Expedition
- POJ 2431 Expedition
- POJ(2431)Expedition
- poj 2431 Expedition
- poj 2431 Expedition
- [POJ 2431]Expedition
- poj 2431 Expedition
- c语言常用技巧
- [NOIP提高组2000]乘积最大
- Mysql的建表规范与注意事项
- java 打印数组内容
- 2017多校5 1006 Rikka with Graph
- 刷题——Expedition POJ
- 《JSP+Servlet+Tomcat》学习笔记(一)
- 让Volt模板引擎在PhpStome中语法高亮
- [USACO]String sobits_01串
- MNIST数据集格式ubyte转png
- Hadoop(3-1)- Yarn 内存分配管理机制及相关参数配置
- Picasso源码解析
- OSI七层网络协议相关概念
- estimateRigidTransform函数在opencv3和opencv2的区别