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

Solution:

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

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

  1. // <travel.cpp> - 06/23/16 12:55:15
  2. // This file is made by YJinpeng,created by XuYike's black technology automatically.
  3. // Copyright (C) 2016 ChangJun High School, Inc.
  4. // I don't know what this program is.
  5.  
  6. #include <iostream>
  7. #include <vector>
  8. #include <algorithm>
  9. #include <cstring>
  10. #include <cstdio>
  11. #include <cstdlib>
  12. #include <cmath>
  13. #define MOD 1000000007
  14. #define INF 1e9
  15. using namespace std;
  16. typedef long long LL;
  17. const int MAXN=100010;
  18. const int MAXM=100010;
  19. inline int max(int &x,int &y) {return x>y?x:y;}
  20. inline int min(int &x,int &y) {return x<y?x:y;}
  21. inline int getint() {
  22. register int w=0,q=0;register char ch=getchar();
  23. while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
  24. if(ch=='-')q=1,ch=getchar();
  25. while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
  26. return q?-w:w;
  27. }
  28. struct Edge{
  29. double p,q;
  30. Edge* next;
  31. };
  32. double d[MAXN],c[MAXN],D,C,V,w[MAXN],ans,k;
  33. int n;
  34. int main()
  35. {
  36. freopen("travel.in","r",stdin);
  37. freopen("travel.out","w",stdout);
  38. scanf("%lf %lf %lf %lf",&D,&C,&V,&w[1]);
  39. n=getint()+1;
  40. for(int i=2;i<=n;i++)scanf("%lf %lf",&d[i],&w[i]);
  41. d[n+1]=D;
  42. for(int i=1;i<=n;i++)c[i]=(d[i+1]-d[i])/V;
  43. Edge* root=new Edge;
  44. Edge* now;Edge* the;
  45. ans=0;c[0]=C;root->next=NULL;
  46. for(int i=1;i<=n;i++){
  47. if(c[i]>C){printf("No Solution");return 0;}
  48. now=root;
  49. while(now->next!=NULL){the=now->next;if(the->q>w[i])break;now=now->next;}
  50. k=c[i-1];the=now;
  51. while(the->next)the=the->next,k+=the->p,ans-=the->p*the->q;
  52. the=new Edge;
  53. the->next=NULL;
  54. the->p=k;the->q=w[i];
  55. now->next=the;now=root->next;
  56. ans+=k*w[i];
  57. k=c[i];
  58. while(k>0){
  59. if(k<now->p){now->p-=k;break;}
  60. k-=now->p;
  61. now=now->next;
  62. }
  63. root->next=now;
  64. }
  65. while(root->next){root=root->next;ans-=root->p*root->q;}
  66. printf("%.2lf",ans);
  67. return 0;
  68. }

  

【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. 关于latch: cache buffers chains的sql优化

    前段时间,优化了一些耗buffer比较多的sql,但是CPU使用率还是没下来 . 查看操作系统CPU使用率 查看awr,发现又有一条超级耗性能的sql冒出来了. 该SQL每次执行耗费3e多个buffe ...

  2. mysql错误Error(1133): Can’t find any matching row in the use

    执行插入用户语句没有问题,但是执行权限赋值的时候提示:1133 - Can't find any matching row in the user table; 解决办法:插入新的用户成功时,需要刷新 ...

  3. c++基础_01字串

    #include <iostream> using namespace std; int main(){ for(int a=0;a<=1;a++){ for(int b=0;b&l ...

  4. 在rubymine中集成heroku插件

    先安装heroku,参见http://www.cnblogs.com/jecyhw/p/4906990.html Heroku安装之后,就自动安装上git,目录为C:\Program Files (x ...

  5. Leetcode 208.实现前缀树

    实现前缀树 实现一个 Trie (前缀树),包含 insert, search, 和 startsWith 这三个操作. 示例: Trie trie = new Trie(); trie.insert ...

  6. Leetcode 187.重复的DNA序列

    重复的DNA序列 所有 DNA 由一系列缩写为 A,C,G 和 T 的核苷酸组成,例如:"ACGAATTCCG".在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮 ...

  7. 九度oj 题目1192:回文字符串

    题目1192:回文字符串 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4391 解决:2082 题目描述: 给出一个长度不超过1000的字符串,判断它是不是回文(顺读,逆读均相同)的. ...

  8. 动态规划之最长递增子序列(LIS)

           在一个已知的序列{ a1,a2,……am}中,取出若干数组成新的序列{ ai1, ai2,…… aim},其中下标 i1,i2, ……im保持递增,即新数列中的各个数之间依旧保持原数列中 ...

  9. 找出消耗CPU最高的进程对应的SQL语句

    COLUMN PID FORMAT 999COLUMN S_# FORMAT 999COLUMN USERNAME FORMAT A9 HEADING "ORA USER"COLU ...

  10. MTK平台 GPU 相关知识

    一.什么是Render script,以及mtk平台GPU support情况 [DESCRIPTION] 1.什么是RenderScript ? 2.RenderScript 干什么? 3.MTK平 ...