ROADS

题目:

N cities named with numbers 1 ... N are connected with one-way roads. Each road has two parameters associated with it : the road length and the toll that needs to be paid for the road (expressed in the number of coins). 
Bob and Alice used to live in the city 1. After noticing that Alice was cheating in the card game they liked to play, Bob broke up with her and decided to move away - to the city N. He wants to get there as quickly as possible, but he is short on cash. 

We want to help Bob to find the shortest path from the city 1 to the city N that he can afford with the amount of money he has. 

Input

The first line of the input contains the integer K, 0 <= K <= 10000, maximum number of coins that Bob can spend on his way. 
The second line contains the integer N, 2 <= N <= 100, the total number of cities. 

The third line contains the integer R, 1 <= R <= 10000, the total number of roads. 

Each of the following R lines describes one road by specifying integers S, D, L and T separated by single blank characters : 

  • S is the source city, 1 <= S <= N 
  • D is the destination city, 1 <= D <= N 
  • L is the road length, 1 <= L <= 100 
  • T is the toll (expressed in the number of coins), 0 <= T <=100


Notice that different roads may have the same source and destination cities.

Output

The first and the only line of the output should contain the total length of the shortest path from the city 1 to the city N whose total toll is less than or equal K coins. 
If such path does not exist, only number -1 should be written to the output. 

Sample Input

5
6
7
1 2 2 3
2 4 3 3
3 4 2 4
1 3 4 1
4 6 2 1
3 5 2 0
5 4 3 2

Sample Output

11

 

题意:

有n个点(编号为1,2,3,,,n),有m条单向路,每条路有相应的长度 l ,以及每条路的花费 t ;

一个人要从1号点走到n号点,问在不超过花费k的情况下最短路是多少。

 

思路:

可以直接用深度优先搜索,只不过在访问每条边时可能会超时,所以用到用数组模拟邻接表。

 

代码:

#include<stdio.h>
#include<string.h>
struct node
{
    int s,d,l,t;
    int next;
}e[10086];
int head[10086],minn,book[10086];
int k,n,m;
void dfs(int x,int s1,int s2)
{//x代表现在的位置,s1代表已经经过的路程,s2表示目前还剩多少钱。
    if(x==n)
    {
        if(s1<minn)
            minn=s1;
        return ;
    }
    for(int i=head[x];i!=-1;i=e[i].next)//跳跃式访问节省时间
    {
    /*  如果这条路中的目标点没访问过,
        且目前访问的路程加上这条路的长度不大于最小长度,
        且加上这条路的花费不大于开始拥有的钱数
    */
        if(!book[e[i].d]&&s1+e[i].l<minn&&s2-e[i].t>=0)
        {
            book[e[i].d]=1;
            dfs(e[i].d,s1+e[i].l,s2-e[i].t);
            book[e[i].d]=0;
        }
    }
}
int main()
{
    while(~scanf("%d%d%d",&k,&n,&m))
    {
        minn=99999999;
        memset(head,-1,sizeof(head));
        memset(book,0,sizeof(book));
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%d%d",&e[i].s,&e[i].d,&e[i].l,&e[i].t);
            e[i].next=head[e[i].s];//用数组模拟邻接表,
            //重新再定义一个next数组也是可以的,为了方便就定义在结构体中。
            head[e[i].s]=i;
        }
        book[1]=1;//标记1号点已经来过
        dfs(1,0,k);
        if(minn==99999999)
            printf("-1\n");
        else
            printf("%d\n",minn);
    }
    return 0;
}

 

### OpenROADS Software Tools or Framework OpenROADS is a comprehensive software suite designed for civil engineering and infrastructure projects, particularly focusing on road and highway design. It provides an integrated environment for planning, designing, analyzing, and managing transportation infrastructure projects. Below are some key aspects of OpenROADS as a software tool or framework: #### 1. **Overview of OpenROADS** OpenROADS is part of the Bentley Systems portfolio, which specializes in software solutions for infrastructure design and management. It supports various stages of the road development lifecycle, including conceptual design, detailed design, analysis, and construction documentation[^5]. #### 2. **Key Features** - **3D Modeling**: OpenROADS offers advanced 3D modeling capabilities that allow engineers to create detailed representations of road networks, bridges, and other infrastructure elements. - **Interoperability**: The software integrates seamlessly with other tools such as MicroStation, GEOPAK, and InRoads, ensuring smooth data exchange and collaboration across teams[^6]. - **Automation and Productivity**: OpenROADS automates repetitive tasks, reducing manual effort and improving productivity in project delivery[^7]. #### 3. **Integration with Requirement Management Tools** While OpenROADS focuses on road design and engineering, it can integrate with requirement management systems like DOORS or Polarion for end-to-end traceability of functional safety requirements[^1]. This ensures alignment between design specifications and project objectives. #### 4. **Simulation and Testing** For autonomous vehicle testing and simulation, OpenROADS can be complemented by tools like AirSim[^3], which provides realistic environments for experimenting with AI-driven algorithms. Although AirSim is primarily used for unmanned vehicles, its integration with OpenROADS could enhance the simulation of traffic scenarios and infrastructure interactions. #### 5. **Data Management and Structured Streaming** In large-scale infrastructure projects, managing vast amounts of data efficiently is crucial. Tools like Apache Spark and Delta Lake[^4] can be leveraged alongside OpenROADS for real-time data processing and analytics, ensuring timely updates and insights during the project lifecycle. ```python # Example of integrating Apache Spark with OpenROADS data from pyspark.sql import SparkSession # Initialize Spark session spark = SparkSession.builder.appName("OpenROADS Data Processing").getOrCreate() # Load OpenROADS-generated data into a DataFrame data = spark.read.format("csv").option("header", "true").load("openroads_data.csv") # Perform transformations and actions filtered_data = data.filter(data["status"] == "completed") summary = filtered_data.groupBy("project_id").count() # Show results summary.show() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值