ZOJ 3699 Dakar Rally

Description

The Dakar Rally is an annual Dakar Series rally raid type of off-road race, organized by the Amaury Sport Organization. The off-road endurance race consists of a series of routes. In different routes, the competitors cross dunes, mud, camel grass, rocks, erg and so on.

Because of the various circumstances, the mileages consume of the car and the prices of gas vary from each other. Please help the competitors to minimize their payment on gas.

Assume that the car begins with an empty tank and each gas station has infinite gas. The racers need to finish all the routes in order as the test case descripts.

Input

There are multiple test cases. The first line of input contains an integer T (T ≤ 50) indicating the number of test cases. Then T test cases follow.

The first line of each case contains two integers: n -- amount of routes in the race; capacity -- the capacity of the tank.

The following n lines contain three integers each: mileagei -- the mileage of the ith route; consumei -- the mileage consume of the car in the ith route , which means the number of gas unit the car consumes in 1 mile; pricei -- the price of unit gas in the gas station which locates at the beginning of the ith route.

All integers are positive and no more than 105.

Output

For each test case, print the minimal cost to finish all of the n routes. If it's impossible, print "Impossible" (without the quotes).

Sample Input
2
2 30
5 6 9
4 7 10
2 30
5 6 9
4 8 10
Sample Output
550
Impossible


题意:给n个加油站, 汽车油箱的容量,之后是每个加油站到下一个的距离,每公里耗油量, 油的单价。求走完所需的最少的金钱,如果不能走完输出Impossible。

思路:一道贪心题。

对于每个加油点判断是否能走到下个站点。

如果不能直接Impossible

如果能,判断下个站点的油价是否小于当前油价

如果小于,则只需在当前站点加油至刚好可以走到下一站点

如果不小于,则继续往后找,直到耗油量大于油箱容量,此时在当前站点加满。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=100005;
struct node
{
    int mile, cost, price;
}point[maxn];
int n, v;
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        bool flag=true;
        scanf("%d%d", &n, &v);
        for(int i=1; i<=n; i++)
        {
            scanf("%d%d%d", &point[i].mile, &point[i].cost, &point[i].price);
            if(point[i].mile*point[i].cost>v)     //判断是否能到达下一站点
                flag=false;
        }
        if(!flag)
        {
            printf("Impossible\n");
            continue;
        }
        long long sum=0;  //记录所需金钱
        long long t=0;    //记录到下个站点所需的油量
        long long r=0;   //记录剩余的油量
        int i=1;
        int j;
        while(i<=n)
        {
            j=i+1;
            t=point[i].mile*point[i].cost;
            while(j<=n&&point[j].price>=point[i].price&&v-t>=point[j].cost*point[j].mile)  //向后找油价便宜的点
            {
                t+=point[j].mile*point[j].cost;
                j++;
            }
            if(j>n||point[j].price<point[i].price)    //找到便宜的
            {
                if(r>t)
                    r-=t;
                else
                {
                    sum+=(t-r)*point[i].price;
                    r=0;
                }
                i=j;
            }
            else   //油箱加满都没找到的
            {
                sum+=(v-r)*point[i].price;
                r=v-point[i].mile*point[i].cost;
                i++;
            }
        }
        printf("%lld\n", sum);
    }
    return 0;
}



【多变量输入超前多步预测】基于CNN-BiLSTM的光伏功率预测研究(Matlab代码实现)内容概要:本文介绍了基于CNN-BiLSTM模型的多变量输入超前多步光伏功率预测方法,并提供了Matlab代码实现。该研究结合卷积神经网络(CNN)强大的特征提取能力与双向长短期记忆网络(BiLSTM)对时间序列前后依赖关系的捕捉能力,构建了一个高效的深度学习预测模型。模型输入包含多个影响光伏发电的气象与环境变量,能够实现对未来多个时间步长的光伏功率进行精确预测,适用于复杂多变的实际应用场景。文中详细阐述了数据预处理、模型结构设计、训练流程及实验验证过程,展示了该方法相较于传统模型在预测精度和稳定性方面的优势。; 适合人群:具备一定机器学习和深度学习基础,熟悉Matlab编程,从事新能源预测、电力系统分析或相关领域研究的研发人员与高校研究生。; 使用场景及目标:①应用于光伏电站功率预测系统,提升电网调度的准确性与稳定性;②为可再生能源并网管理、能量存储规划及电力市场交易提供可靠的数据支持;③作为深度学习在时间序列多步预测中的典型案例,用于科研复现与教学参考。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,重点关注数据归一化、CNN特征提取层设计、BiLSTM时序建模及多步预测策略的实现细节,同时可尝试引入更多外部变量或优化网络结构以进一步提升预测性能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值