patA1033 to fill or not fill

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
//在汽车的行驶过程中,如果有更便宜的,选择便宜的,加一定量。去下一个更便宜的。 
//有没有必要计算俩个加油点的距离?
//又没有必要对距离原点的距离进行排序? 
struct postion{
double per_price;
int dis_h;
bool operator <(const postion &a)const {
return dis_h < a.dis_h;

}p[1001];
int main(int argc, char** argv) {
int tank,Distance,cell_run,n;
scanf("%d %d %d %d",&tank,&Distance,&cell_run,&n);
for(int i=0;i<n;i++){
scanf("%lf %d",&p[i].per_price,&p[i].dis_h);
}
int tank_run=cell_run*tank;     //每次走的最大的距离; 
double ans=0;
int have_run=0;
//初始可以行走的最大的距离;
sort(p,p+n); 
if(p[0].dis_h!=0) printf("The Max travel distance = 0.00");
else{
int key=0; //查找在一段距离中油价低的第一个;
for(int i=0;i<n;i++){ 
if(p[i].dis_h<=tank_run && p[key].per_price<p[i].per_price) key=i;
}
if(key!=0){
have_run+=p[key].dis_h-0;
ans+=(have_run/cell_run)*p[0].per_price;       //累计的钱; 
}else{
 

}
return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37816373/article/details/80213818
今日推荐