BZOJ1747 [Usaco2005 open]Expedition 探险
首先我们可以发现如果错过了一个加油站,而继续往前走的时候没有油了,可以再假装之前经过加油站的时候加过油
于是我们维护一个大根堆,表示错过的加油站是哪些,每当没有油的时候从堆顶取出最大值加上去即可
/**************************************************************
Problem: 1747
User: rausen
Language: C++
Result: Accepted
Time:20 ms
Memory:916 kb
****************************************************************/ #include <cstdio>
#include <algorithm>
#include <queue> using namespace std;
const int N = 1e4 + ; inline int read(); struct data {
int w, add; inline void get() {
w = read(), add = read();
} inline bool operator < (const data &d) const {
return w > d.w;
}
} a[N]; int n, tot, ans;
priority_queue <int> h; int main() {
int i;
n = read();
for (i = ; i <= n; ++i) a[i].get();
a[].w = read(), tot = read();
sort(a + , a + n + );
a[n + ].w = ;
for (i = ; i <= n + ; ++i) {
tot -= (a[i - ].w - a[i].w);
while (tot < && !h.empty()) {
++ans;
tot += h.top(), h.pop();
}
if (tot < ) {
puts("-1");
return ;
}
h.push(a[i].add);
}
printf("%d\n", ans);
return ;
} inline int read() {
static int x;
static char ch;
x = , ch = getchar();
while (ch < '' || '' < ch)
ch = getchar();
while ('' <= ch && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return x;
}
BZOJ1747 [Usaco2005 open]Expedition 探险的更多相关文章
- BZOJ-USACO被虐记
bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- POJ 2431 Expedition(探险)
POJ 2431 Expedition(探险) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] A group of co ...
- Planning The Expedition(暴力枚举+map迭代器)
Description Natasha is planning an expedition to Mars for nn people. One of the important tasks is t ...
- 【BZOJ1672】[Usaco2005 Dec]Cleaning Shifts 清理牛棚 动态规划
[BZOJ1672][Usaco2005 Dec]Cleaning Shifts Description Farmer John's cows, pampered since birth, have ...
- 【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理 状压DP
[BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) ...
- 【BZOJ1671】[Usaco2005 Dec]Knights of Ni 骑士 BFS
[Usaco2005 Dec]Knights of Ni 骑士 Description 贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为 ...
- POJ 2431 Expedition(优先队列、贪心)
题目链接: 传送门 Expedition Time Limit: 1000MS Memory Limit: 65536K 题目描述 驾驶一辆卡车行驶L单位距离.最开始有P单位的汽油.卡车每开1 ...
- ASP.NET 5探险(3):使用UMEditor并实现图片上传
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:今天将继续上一篇来讲解百度富文本Web编辑器UEditor或UMEditor的使用. ...
随机推荐
- .NET在后置代码中输入JS提示语句(背景不会变白)
来源:http://niunan.iteye.com/blog/248256 Page.ClientScript.RegisterStartupScript(Page.GetType(), " ...
- HDU 5430 Reflect(欧拉函数)
题目: http://acm.hdu.edu.cn/showproblem.php?pid=5430 从镜面材质的圆上一点发出一道光线反射NNN次后首次回到起点. 问本质不同的发射的方案数. 输入描述 ...
- JQery 中的 $(".bb:eq(1)") eq () 解释。。
这是一段代码: <div id="bb">a</div> <div id="bb">b</div> <di ...
- MVC服务器前台提示
[HttpPost] public ActionResult AddMsg(MsgModel model) { string strSql = "insert into tbl_msg(ti ...
- 无法在web服务器上启动调试。打开的URL的IIS辅助进程当前没有运行。
调试时弹出:无法在web服务器上启动调试.打开的URL的IIS辅助进程当前没有运行.
- Jquery 移除 html中绑定的onClick事件
HTML绑定示例: <button class="edit" onClick="showTurnEdit(this)">编辑</button& ...
- 无限极分类,传递一个子ID得到所有父集,用于在前台分层显示标题
方法: static public function getParents($data,$id){ $arr=array(); foreach ($data as $v) { if ($v['id'] ...
- 【ufldl tutorial】Softmax Regression
今天太长姿势了,什么叫懂了也写不出代码说的不就是我吗,就那么几行代码居然叽叽歪歪写了一个小时. 首先exercise要实现的是softmax的cost function和gradient,如下图: ( ...
- request is not finfished yet!
在项目测试的时候发现一个问题.当数据量特别多的时候,我一次性查询几万条数据的时候,就会出现很卡很慢的状态. 我把sql优化了,但是出现同样的问题.我要从后台得到数据显示在页面上来.就需要知道是查询慢, ...
- 车辆管理系统之搭建框架 添加必要的数据 安装svn(二)
JAVA EE第一阶段项目——车辆管理系统.MyEclipse + MySQL +powerDesinger +tomcat +svn. 今天组长把项目的分工安排好了!这个周末两天的作业就是我的车主信 ...