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 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
随机推荐
- [WPF系列]-Layout
DockPanel The nice thing about dock panels is they already fill all the available space. LastChildFi ...
- 尽量不要用ad,adv···,advertisement 这些关键词命名
html dom,文件夹名称,文件名称·······,都尽量不用ad,adv···,advertisement 这些关键词! 为嘛呢? 因为会被浏览器的广告插件自动给屏蔽掉. 我的网站中有一个广告管 ...
- 洛谷P2055 [ZJOI2009]假期的宿舍 [二分图最大匹配]
题目描述 学校放假了 · · · · · · 有些同学回家了,而有些同学则有以前的好朋友来探访,那么住宿就是一个问题.比如 A 和 B 都是学校的学生,A 要回家,而 C 来看B,C 与 A 不认识. ...
- UVA - 1025 A Spy in the Metro[DP DAG]
UVA - 1025 A Spy in the Metro Secret agent Maria was sent to Algorithms City to carry out an especia ...
- AC日记——苹果树 codevs 1228
1228 苹果树 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 在卡卡的房子外面,有一棵 ...
- 软件工程导论-目录-K-T+RJ大
目录 10 第1章 软件工程学概述/1 19 1.1 软件危机/1 19 1.1.1 软件危机的介绍/1 19 1.1.2 产生软件危机的原因/3 21 1.1.3 消除软件危机的途径/4 22 1. ...
- js实现弹框及自动关闭
<SCRIPT LANGUAGE="javascript"> < !-- window.open (''page.html'',''newwindow'',''h ...
- 我为什么还要造轮子?欠踹?Monk.UI表单美化插件诞生记!
背景 目前市场上有很多表单美化的UI,做的都挺不错,但是他们都有一个共同点,那就是90%以上都是前端工程师开发的,导致我们引入这些UI的时候,很难和程序绑定.所以作为程序员的我,下了一个决定!我要自己 ...
- iOS中多线程常用的知识点
1.pThread 跨平台的多线程技术 , 是IEEE制定的POSIX 表示可移植性操作系统接口的多线程计数,UNIX内核平台 Unix,Linux,Mac(小红帽) (windows上有可移 ...
- prototype 原型
在我刚学习javascript的时候对于原型的概念很模糊,现在也不是很懂,希望下面的文章对有相同问题的朋友有帮助,如果有误希望指正: prototype用于通常用于构造函数中,公用方法的继承上.构造函 ...