文章

4

粉丝

302

获赞

1

访问

40.1k

头像
感觉相对来说我这个还简单点就写个题解
P1347 浙江大学机试题
发布于2020年2月26日 22:50
阅读数 9.0k

核心代码就是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...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发