1033. To Fill or Not to Fill
来源:互联网 发布:服务器机柜和网络机柜 编辑:程序博客网 时间:2024/05/14 05:30
看当前站可达范围内的加油站,加足够的油到第一个更便宜的站,或者加满油到紧邻的下一个站
#include<algorithm>#include<iostream>using namespace std;int cmax,dist,davg,n;double cost,leftoil,maxlen;struct node{int d; double p; node(double a,int b):p(a),d(b){} bool operator<(const node&x)const{return d<x.d;}};vector<node>st;int nextst(int k){ int maxlen=cmax*davg,next=-1; for(int i=k+1,mmin=1<<30;i<=n&&st[i].d<=st[k].d+maxlen;++i) if(st[i].p<st[k].p)return i; if(st[k+1].d<=st[k].d+maxlen) return k+1; return -1;}int main(){ cin>>cmax>>dist>>davg>>n; for(int i=0;i<n;++i){ double a,b; cin>>a>>b; if(b<dist) st.emplace_back(a,b); } sort(st.begin(),st.end()); st.emplace_back(0.0,dist); if(st[0].d) {maxlen=0.0003;goto hehe;} for(int next,i=0;i<n;i=next){ next=nextst(i); if(next==-1) { maxlen=st[i].d+cmax*davg; break; }else{ double needoil=double(st[next].d-st[i].d)/davg; if(st[next].p<st[i].p){cost+=max((needoil-leftoil)*st[i].p,0.0);leftoil=max(leftoil-needoil,0.0); }else{cost+=(cmax-leftoil)*st[i].p;leftoil=cmax-needoil; }//else }//else }//for hehe: if(maxlen>0.0002)printf("The maximum travel distance = %.2lf",maxlen); else printf("%.2lf",cost);}
0 0
- 1033. To Fill or Not to Fill
- 1033. To Fill or Not to Fill
- 1033. To Fill or Not to Fill
- 1033. To Fill or Not to Fill
- 1033. To Fill or Not to Fill
- 1033. To Fill or Not to Fill
- 1033. To Fill or Not to Fill
- *1033. To Fill or Not to Fill
- 1033. To Fill or Not to Fill
- To Fill or Not to Fill
- To Fill or Not to Fill
- PAT_1033. To Fill or Not to Fill
- 1033. To Fill or Not to Fill (25)
- 1033. To Fill or Not to Fill (25)-PAT
- 【PAT】1033. To Fill or Not to Fill (25)
- 1033. To Fill or Not to Fill (25)
- PAT 1033. To Fill or Not to Fill (25)
- 1033. To Fill or Not to Fill (25)
- 《Linux设备驱动开发详解》——I2C核心、总线与设备驱动
- [LeetCode]Merge Sorted Array
- 我的CSDN博客世界:欢迎切磋和交流
- HDU 4417 Super Mario
- 【IPV6基础知识】IPV6地址结构
- 1033. To Fill or Not to Fill
- Ubuntu 配置 Tomcat与日常错误解决
- android学习笔记(2.1)--7.20--(5中布局方式+android单位)
- Ubuntu字典app开发(二)——探索与实践
- poj 2240 Arbitrage
- java压缩处理Image图片
- hdu 1257 动态规划
- hdu 1420 Prepared for New Acmer(快速幂入门)
- GetLastError函数返回值的含义