|
- #include <algorithm>
- #include <iostream>
- #include <cmath>
- #include <cstring>
- #include <map>
- #include <string>
- #include <vector>
- #include <queue>
- #include <stack>
- #include <cstdio>
- #include <cstdlib>
- using namespace std;
- double d[1000]={0},p[1000],dm,s,c,money=0,oil=0;
- int n;
- void aha(int mu,int no,int l)
- {
- if(no==n+1)
- {
- printf("%.2lf",money);
- return ;
- }
- if(no<mu)
- {
- int e=l;
- if(p[no]<p[l])
- money-=oil*(p[l]-p[no]),e=no;
- oil-=(d[no+1]-d[no])/dm;
- aha(mu,no+1,e);
- return ;
- }
- else if(no==mu)
- {
- int k=no+1;
- while(p[k]>p[no])
- k++;
- if(d[k]-d[no]<=dm*c)//跑得到
- {
- if(oil<(d[k]-d[no])/dm)
- {
- money+=((d[k]-d[no])/dm-oil)*p[no];
- oil=(d[k]-d[no])/dm;
- }
- aha(k,no,no);
- return ;
- }
- else//跑不到
- {
- int t=no+1;
- while(d[t]-d[no]<=dm*c)//跑的越远越好
- t++;
- money+=(c-oil)*p[no],oil=c;
- aha(t-1,no,no);
- return ;
- }
- }
- }
- int main()
- {
- scanf("%lf%lf%lf%lf%d",&s,&c,&dm,&p[0],&n);
- for(int i=1;i<=n;++i)
- {
- scanf("%lf%lf",&d[i],&p[i]);
- if(d[i]-d[i-1]>dm*c)
- {
- printf("No Solution");
- return 0;
- }
- }
- d[n+1]=s;
- if(d[n+1]-d[n]>dm*c)
- {
- printf("No Solution");
- return 0;
- }
- aha(0,0,0);
- return 0;
- }
复制代码 |
|