蒟蒻BUG程序请神犇赐教

#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
typedef struct 
{
  double lg,mo;
}score;
score stop[110];
double d1,d2,c,p,now,money,num;
int n,car;
int main()
{
  cin>>d1>>c>>d2>>p>>n;
  for(int i=1;i<=n;i++)
    cin>>stop[i].lg>>stop[i].mo;
  stop[0].mo=p;
  stop[0].lg=0;
  stop[n+1].lg=d1;
  stop[n+1].mo=p;
  for(;car<=n;)
  {
    int MIN=-1;
    num=99999.0;
    for(int i=car+1;stop[i].lg<=c*d2 && i<=n+1;i++)
      if(stop[i].mo<=num)
      {
        num=stop[i].mo;
        MIN=i;
      }
    if(MIN==-1)
    {
      cout<<"-1";
      return 0;
    }
    else
      if(stop[MIN].mo<stop[car].mo)
      {
        if(now*d2>=stop[MIN].lg-stop[car].lg)
        {
          now=now-(stop[MIN].lg-stop[car].lg)/d2;
          car=MIN;
        }
        else
        {
          money=money+(stop[MIN].lg-stop[car].lg-now*d2)/d2*stop[car].mo;
          now=0;
          car=MIN;
        }
      }
      else
      {
        if(MIN!=n+1)
          money=money+(c-now)*stop[car].mo;
        else if(now*d2<d1-stop[car].lg)
          money=money+(d1-stop[car].lg-now*d2)/d2*stop[car].mo;
        now=c;
        now=now-(stop[MIN].lg-stop[car].lg)/d2;
        car=MIN;
      }
  }
  money*=100;
  round(money);
  money/=100;
  printf("%.2f",money);
  return 0;
}

1 条评论

  • 1

信息

ID
1253
难度
6
分类
贪心 点击显示
标签
递交数
3363
已通过
807
通过率
24%
被复制
16
上传者