http://codevs.cn/problem/1046/

Solution:

贪心,如果当前油价很低,它就比起当前剩余油的价还低就可以替换,并且每次加满,最后把剩的油卖掉即可

油价用单调链表(不知到为什么会写链表,脑抽,当时觉得插入方便,其实不用插入。。。尴尬)维护 or 堆(你也可以脑抽,加个log),没事啦,数据水

// <travel.cpp> - 06/23/16 12:55:15
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
using namespace std;
typedef long long LL;
const int MAXN=100010;
const int MAXM=100010;
inline int max(int &x,int &y) {return x>y?x:y;}
inline int min(int &x,int &y) {return x<y?x:y;}
inline int getint() {
register int w=0,q=0;register char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')q=1,ch=getchar();
while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
return q?-w:w;
}
struct Edge{
double p,q;
Edge* next;
};
double d[MAXN],c[MAXN],D,C,V,w[MAXN],ans,k;
int n;
int main()
{
freopen("travel.in","r",stdin);
freopen("travel.out","w",stdout);
scanf("%lf %lf %lf %lf",&D,&C,&V,&w[1]);
n=getint()+1;
for(int i=2;i<=n;i++)scanf("%lf %lf",&d[i],&w[i]);
d[n+1]=D;
for(int i=1;i<=n;i++)c[i]=(d[i+1]-d[i])/V;
Edge* root=new Edge;
Edge* now;Edge* the;
ans=0;c[0]=C;root->next=NULL;
for(int i=1;i<=n;i++){
if(c[i]>C){printf("No Solution");return 0;}
now=root;
while(now->next!=NULL){the=now->next;if(the->q>w[i])break;now=now->next;}
k=c[i-1];the=now;
while(the->next)the=the->next,k+=the->p,ans-=the->p*the->q;
the=new Edge;
the->next=NULL;
the->p=k;the->q=w[i];
now->next=the;now=root->next;
ans+=k*w[i];
k=c[i];
while(k>0){
if(k<now->p){now->p-=k;break;}
k-=now->p;
now=now->next;
}
root->next=now;
}
while(root->next){root=root->next;ans-=root->p*root->q;}
printf("%.2lf",ans);
return 0;
}

  

【NOIP1999】【Codevs 1046】旅行家的预算的更多相关文章

  1. codevs 1046 旅行家的预算

    传送门 1046 旅行家的预算 1999年NOIP全国联赛普及组NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold题解   题目描述 Des ...

  2. 洛谷 1016 / codevs 1046 旅行家的预算

    https://www.luogu.org/problem/show?pid=1016 http://codevs.cn/problem/1046/ 题目描述 Description 一个旅行家想驾驶 ...

  3. 旅行家的预算(NOIP1999&水题测试2017082301)

    题目链接:旅行家的预算 这题还可以,不算太水. 这题贪心即可. 我们采取如下动作: 如果在装满油的情况下能到达的范围内,没有加油站,则无解. 如果在装满油的情况下能到达的范围内,油价最低的加油站的油价 ...

  4. 洛谷 P1016 旅行家的预算

    P1016 旅行家的预算 题目OJ链接https://www.luogu.org/problemnew/show/P1016 题目描述一个旅行家想驾驶汽车以最少的费用从一个城市到另一个城市(假设出发时 ...

  5. 蓝桥杯 算法训练 ALGO-15 旅行家的预算

    算法训练 旅行家的预算   时间限制:1.0s   内存限制:256.0MB 问题描述 一个旅行家想驾驶汽车以最少的费用从一个城市到另一个城市(假设出发时油箱是空的).给定两个城市之间的距离D1.汽车 ...

  6. P1016 旅行家的预算

    P1016 旅行家的预算 题目描述 一个旅行家想驾驶汽车以最少的费用从一个城市到另一个城市(假设出发时油箱是空的).给定两个城市之间的距离D1.汽车油箱的容量C(以升为单位).每升汽油能行驶的距离D2 ...

  7. P1016 旅行家的预算——贪心

    P1016 旅行家的预算 贪心求,在当前点如果能到达距离最近的油价比他小的就直接去油价比他小的, 如果在可行范围内没有比他油价小的,就加满开到可行范围内油价最小的点: 这么做是对的,我不会证明: 还有 ...

  8. [luogu]P1016 旅行家的预算[贪心]

    [luogu]P1016 旅行家的预算 题目描述 一个旅行家想驾驶汽车以最少的费用从一个城市到另一个城市(假设出发时油箱是空的).给定两个城市之间的距离D1.汽车油箱的容量C(以升为单位).每升汽油能 ...

  9. 洛谷 P1016 旅行家的预算 模拟+贪心

    目录 题面 题目链接 题目描述 输入输出格式 输入格式 输出格式 输入输出样例 输入样例 输出样例 说明 思路 AC代码 总结 题面 题目链接 P1016 旅行家的预算 题目描述 一个旅行家想驾驶汽车 ...

随机推荐

  1. Go:面向"对象"

    一.封装 封装的实现步骤: 将结构体.字段的首字母小写(不能被导出): 给结构体所在的包提供一个工厂模式的函数,首字母大写.类似一个构造函数: 提供一个首字母大写的方法,由于获取结构体属性的值. 二. ...

  2. Why Countries Succeed and Fail Economically

    Countries Succeed and Fail Economically(第一部分)" title="Why Countries Succeed and Fail Econo ...

  3. 在docker下面安装Nginx PHP mysql let's encrypt

    最近自己在弄了个Nginx PHP Mysql Let's encrypt的docker,下面记录一下 1)先装 Let's encrypt docker run --rm -p 80:80 -p 4 ...

  4. Automation 的 Wait 工具

    public static WebDriverWait createWait(WebDriver driver) { return new WebDriverWait(driver, Environm ...

  5. [luoguP1440] 求m区间内的最小值(单调队列 || 线段树)

    传送门 这种水题没必要搞线段树了,单调队列就行啊. ——代码 #include <cstdio> ; , t = ; int a[MAXN], q[MAXN]; int main() { ...

  6. 【BZOJ4872】分手是祝愿(期望DP)

    题意: B 君在玩一个游戏,这个游戏由 n 个灯和 n 个开关组成,给定这 n 个灯的初始状态,下标为 从 1 到 n 的正整数.每个灯有两个状态亮和灭,我们用 1 来表示这个灯是亮的,用 0 表示这 ...

  7. 无法打开物理文件 "X.mdf"。操作系统错误 5:"5(拒绝访问。)"。 (Microsoft SQL Server,错误: 5120)解决

    环境 SQLServer 2008 R2 问题 附加数据库出现“无法打开物理文件 "X.mdf".操作系统错误 5:"5(拒绝访问.)". (Microsoft ...

  8. HDU——1068 Girls and Boys

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. 基于 Java 的开源网络爬虫框架 WebCollector

    原文:https://www.oschina.net/p/webcollector

  10. Centos 备份 还原

    備份: tar cvpzf backup.tgz / --exclude=/backup.tgz --exclude=/mnt 記得一定要排除備份文件本身哦! 還原: tar xvpfz backup ...