文章
4
粉丝
302
获赞
1
访问
41.9k
核心代码就是Loop函数里面for循环的内容了,加起来10行多一点,应该算比较简单吧~~(大概)
struct node
{
double price;
double dist;
};
struct print
{
int flag;
double pri;
};
bool cmpD(node a, node b)
{
return a.dist <= b.dist;
}
print Loop(int cmax, int davg, int num, double D)
{
print aaa;
node gas[num + 2];
//将单位油价格,转为单位距离价格
for (int i = 1; i < num + 1; i++)
{
double uprice;
cin >> uprice >> gas[i].dist;
gas[i].price = uprice / davg;
}
//按照距离排序
sort(gas + 1, gas + num + 1, cmpD);
double run_max = cmax * davg * 1.0;
double run_fina = 0, run_left = 0;
double ival;
double pri_fina = 0, price_now = 9999;
gas[num + 1].dist = D;
for (int i = 1; i < num + 1; i++)
{
ival = gas[i + 1].dist - gas[i].dist;
//是否能跑完
if (run_max < ival)
{
run_fina += run_max;
// cout << "The maxi...
登录后发布评论
暂无评论,来抢沙发