1 条题解

  • 0
    @ 2021-6-14 23:25:26

    C :

    #include <stdio.h>
    #define N 1024
    
    int main()
    {
        int i,j,k,n;
        double d1,c,d2,p[N][2]={0},f,min;
        scanf("%lf%lf%lf%lf%d",&d1,&c,&d2,&p[0][1],&n);
        n++;
        for (i=1;i<n;i++)
            scanf("%lf%lf",&p[i][0],&p[i][1]);
        p[n++][0]=d1;
        f=c*d2;
        for(i=0;i<n;i++)
        {
            if (p[i+1][0]-p[i][0]>f)
            {
                printf("No Solution");
                return 0;
            }
        }
        k =0;
        min=0;
        for (i=0;i<n-1;i++)
        {
            double d=p[i+1][0]-p[i][0];
            while(d)
            {
                while(p[i+1][0]-p[k][0]-d>= f)
                    k++;
                for(j=k;j<= i;j++)
                    if (p[j][1]<p[k][1])
                        k=j;
                double max=f-(p[i+1][0]-p[k][0]-d);
                if(max>d)max=d;
                d-=max;
                min+=max/d2*p[k][1];
            }
        }
        printf("%.2lf\n",min);
        return 0;
    }
    

    C++ :

    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    #include<queue>
    #define INF 10000000
    #define N 1000010
    using namespace std;
    double ci[N],pi[N];
    double dp[N];
    int main()
    {
        double l,c,m,s;
        int n;
        while(cin>>l>>c>>m>>pi[0]>>n)
        {
            for(int i=1;i<=n;i++)
            {
                scanf("%lf%lf",&ci[i],&pi[i]);
            }
            ci[0]=0,ci[n+1]=l,pi[n+1]=INF;
            s=c*m;
            for(int i=0;i<=n+1;i++)
                dp[i]=INF;
            dp[0]=0;
            int flag=0;
            for(int i=0;i<=n;i++)
            {
                for(int j=i+1;j<=n+1;j++)
                {
                    if(s>=ci[j]-ci[i])
                    {
                        dp[j]=min(dp[j],dp[i]+pi[i]*(ci[j]-ci[i])/m);
                    }
                    else
                    {
                        if(s>=ci[j]-ci[j-1])
                            dp[j]=min(dp[j],dp[i]+(pi[i]*s+pi[j-1]*(ci[j]-ci[i]-s))/m);
                        else
                        {
                            flag=1;
                            break;
                        }
                    }
                }
                if(flag==1)
                    break;
            }
            if(dp[n+1]==INF)
                cout<<"No Solution"<<endl;
            else
                printf("%.2lf\n",dp[n+1]);
        }
        return 0;
    }
    

    Pascal :

    var dis,c,m,l,ans,t:real;
        n,i,j:longint;
        over,x,p,d:array[0..1000] of real;
    begin
      readln(dis,c,m,p[0],n);
      l:=c*m;
      for i:=1 to n do
        readln(d[i],p[i]);
      d[n+1]:=dis;
      for i:=1 to n+1 do
        if d[i]-d[i-1]>l then begin writeln('No Solution'); exit end;
      i:=0;
      repeat
        for j:=i+1 to n+2 do
          if (d[j]-d[i]<=l) and (p[j]<p[i]) then break;
        t:=(d[j]-d[i])/m;
        if j<>n+2 then
        begin
          if over[i]>=t then
            over[j]:=over[i]-t
          else
            x[i]:=t-over[i]
        end
        else
        begin
          x[i]:=c-over[i];
          j:=i+1;
          over[j]:=c-(d[j]-d[i])/m;
        end;
        i:=j;
      until i=n+1;
      for i:=0 to n do
        ans:=ans+p[i]*x[i];
      writeln(ans:0:2);
    end.
    
    • 1

    信息

    ID
    194
    时间
    1000ms
    内存
    125MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者