ZOJ 3699 Dakar Rally
Dakar Rally
Time Limit: 2 Seconds Memory Limit: 65536 KB
Description
The Dakar Rally is an annual Dakar Series rally raid type of off-road race, organized by the Amaury Sport Organization. The off-road endurance race consists of a series of routes. In different routes, the competitors cross dunes, mud, camel grass, rocks, erg and so on.
Because of the various circumstances, the mileages consume of the car and the prices of gas vary from each other. Please help the competitors to minimize their payment on gas.
Assume that the car begins with an empty tank and each gas station has infinite gas. The racers need to finish all the routes in order as the test case descripts.
Input
There are multiple test cases. The first line of input contains an integer T (T ≤ 50) indicating the number of test cases. Then T test cases follow.
The first line of each case contains two integers: n -- amount of routes in the race; capacity -- the capacity of the tank.
The following n lines contain three integers each: mileagei -- the mileage of the ith route; consumei -- the mileage consume of the car in the ith route , which means the number of gas unit the car consumes in 1 mile; pricei -- the price of unit gas in the gas station which locates at the beginning of the ith route.
All integers are positive and no more than 105.
Output
For each test case, print the minimal cost to finish all of the n routes. If it's impossible, print "Impossible" (without the quotes).
Sample Input
2
2 30
5 6 9
4 7 10
2 30
5 6 9
4 8 10
Sample Output
550
Impossible
Author: OUYANG, Jialin
Contest: The 13th Zhejiang University Programming Contest
用一个双端队列维护,使容量为C的油箱中,便宜的油的比例最大,并优先使用便宜的油。。。。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <deque>
#include <cmath> using namespace std; typedef long long int LL; struct ROAD
{
int m,c,p,cpm;
}road[]; struct OIL
{
int P,L;
bool operator<(OIL t) const
{
return P>t.P;
}
}; int N,C,t; LL solve()
{
LL ret=;
int vol=;///zhong gong C L de you
deque<OIL> dq;
for(int i=;i<=N;i++)
{
while(vol&&!dq.empty()&&dq.back().P>road[i].p)
{
vol-=dq.back().L;
dq.pop_back();
}
OIL t; t.L=C-vol; t.P=road[i].p;
vol=C-road[i].cpm;
dq.push_back(t);
int youliang=road[i].cpm;
while(youliang>)
{
OIL& cur=dq.front();
int Minn=min(cur.L,youliang);
ret+=(LL)Minn*cur.P;
youliang-=Minn; cur.L-=Minn;
if(!cur.L) dq.pop_front();
}
}
return ret;
} int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&N,&C);
bool flag=true;
for(int i=;i<=N;i++)
{
scanf("%d%d%d",&road[i].m,&road[i].c,&road[i].p);
road[i].cpm=road[i].c*road[i].m;
if(road[i].cpm>C) flag=false;
}
if(flag==false) puts("Impossible");
else printf("%lld\n",solve());
}
return ;
}
ZOJ 3699 Dakar Rally的更多相关文章
- ZOJ 3699 Dakar Rally(贪心)
这是一道贪心题,他的贪心思想很容易想明白,我们保证油箱里的油始终是最便宜的我们最后的花费就能是最少的.实现方法就是:比如现在在i点,我们看邮箱满载能最远到达哪里,不妨设最远到达j,(j >= i ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
- zoj 1788 Quad Trees
zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
随机推荐
- MySQL命令行登录的例子
环境:MySQL Sever 5.1 + MySQL命令行工具 问题:MySQL命令行登录 解决: 命令 行登录语法: mysql –u用户名 [–h主机名或者IP地址] –p密码 说明:用户名是你登 ...
- 洛谷P3406 海底高铁[差分 贪心]
题目背景 大东亚海底隧道连接着厦门.新北.博艾.那霸.鹿儿岛等城市,横穿东海,耗资1000亿博艾元,历时15年,于公元2058年建成.凭借该隧道,从厦门可以乘坐火车直达台湾.博艾和日本,全程只需要4个 ...
- 前端之css
前端之css 本节内容 css概述及引入 css选择器 css常用属性 1.css概述及引入 CSS概述 CSS是Cascading Style Sheets的简称,中文称为层叠样式表,用来控制网页数 ...
- [转载]jQuery中wrap、wrapAll和wrapInner用法以及区别
原文地址:jQuery中wrap.wrapAll和wrapInner用法以及区别作者:伊少君 原文: <ul> <li title='苹果'>苹果</li> ...
- FFT
void FFT(complex a[],int n,int fl){ ,j=n/;i<n;i++){ if (i<j) {complex t=a[i];a[i]=a[j];a[j]=t; ...
- JQuery中Ajax的操作
JQuery Ajax异步操作的方式: $.ajax,$.post, $.get, $.getJSON. 一, $.ajax,这个是JQuery对ajax封装的最基础步,通过使用这个函数可以完成异 ...
- 高性能集群软件Keepalived(1)
1介绍 Keepalived是linux下一个轻量级的高可用解决方案,与HeartBeat,RoseHA实现的功能类似,但是还是有差别.HeartBeat是一个专业的功能完善的高可用软件,它提供了HA ...
- Cocos2d-X3.0 刨根问底(四)----- 内存管理源码分析
本系列文章发表以来得到了很多朋友的关注,小鱼在这里谢谢大家对我的支持,我会继续努力的,最近更新慢了一点,因为我老婆流产了抽了很多时间来照顾她希望大家谅解,并在此预祝我老婆早日康复. 上一篇,我们完整的 ...
- js jquery 选择器总结
js jquery 选择器总结 一.原始JS选择器. id选择器:document.getElementById("test"); name选择器:document.getElem ...
- 【Beta】第四次任务发布
PM 日常管理&dev版宣传(周日开始). 后端 #99 服务发布 验收条件:使dev版能在www.buaaphylab.com下运行. 前端 #87 登录后能够查看与下载用户收藏的报告.生成 ...