1111 Online Map (30分)

本文探讨了在给定地图上寻找从起点到终点的最短路径和最快路径的问题,通过对比深度优先搜索(DFS)和迪杰斯特拉算法(Dijkstra),详细解释了如何在考虑距离和时间两个因素的情况下找到最优解。

Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is the fastest. It is guaranteed that a path exists for any request.

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers N (2≤N≤500), and M, being the total number of streets intersections on a map, and the number of streets, respectively. Then M lines follow, each describes a street in the format:

V1 V2 one-way length time

where V1 and V2 are the indices (from 0 to N−1) of the two ends of the street; one-way is 1 if the street is one-way from V1 to V2, or 0 if not; length is the length of the street; and time is the time taken to pass the street.

Finally a pair of source and destination is given.

Output Specification:

For each case, first print the shortest path from the source to the destination with distance D in the format:

Distance = D: source -> v1 -> ... -> destination

Then in the next line print the fastest path with total time T:

Time = T: source -> w1 -> ... -> destination

In case the shortest path is not unique, output the fastest one among the shortest paths, which is guaranteed to be unique. In case the fastest path is not unique, output the one that passes through the fewest intersections, which is guaranteed to be unique.

In case the shortest and the fastest paths are identical, print them in one line in the format:

Distance = D; Time = T: source -> u1 -> ... -> destination

Sample Input 1:

10 15
0 1 0 1 1
8 0 0 1 1
4 8 1 1 1
3 4 0 3 2
3 9 1 4 1
0 6 0 1 1
7 5 1 2 1
8 5 1 2 1
2 3 0 2 2
2 1 1 1 1
1 3 0 3 1
1 4 0 1 1
9 7 1 3 1
5 1 0 5 2
6 5 1 1 2
3 5

Sample Output 1:

Distance = 6: 3 -> 4 -> 8 -> 5
Time = 3: 3 -> 1 -> 5

Sample Input 2:

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

Sample Output 2:

Distance = 3; Time = 4: 3 -> 2 -> 5

思路:题目比较常规,使用DFS最后一个节点超时,最后使用Dijkstra来AC,注释部分为DFS代码~ 

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;


int n, m;
vector<vector<int> > vec;
// vector<int> temp_path;
// vector<int> dis_path;
// vector<int> time_path;
// bool visit[501] = {false};
int graph_length[501][501] = {0};
int graph_time[501][501] = {0};
// int min_dis = 0x7fffffff;
// int min_dis_time = 0x7fffffff;
// int min_time = 0x7fffffff;
// int min_time_section = 0x7fffffff;
// void dfs(int start, int end, int dis, int time){ // 使用dfs最后一个节点超时,very sorrow~
//     if(start == end){
//         if(dis < min_dis || (dis == min_dis && time < min_dis_time)){
            
//             min_dis = dis;
//             dis_path = temp_path;
//             min_dis_time = time;
//         }
//         if(time < min_time || (time == min_time && temp_path.size() < min_time_section)){          
//             min_time = time;
//             time_path = temp_path;
//             min_time_section = temp_path.size();
//         }
//         return;
//     }
//    for(int i = 0; i < vec[start].size(); i++){
//         if(!visit[vec[start][i]]){
//             temp_path.push_back(vec[start][i]);
//             visit[vec[start][i]] = true;
//             dfs(vec[start][i], end, dis + graph_length[start][vec[start][i]], time + graph_time[start][vec[start][i]]);
//             visit[vec[start][i]] = false;
//             temp_path.pop_back();
//         }        
//     }
// }
int dij_dis[501];
int dij_time[501];
int dij_path[501];
int dij_visit[501];
const int max_init = 99999999;
void dis_dijkstra(int start){
    fill(dij_dis, dij_dis + 501, max_init);
    fill(dij_visit, dij_visit + 501, false);
    dij_dis[start] = 0;

    for(int i = 0; i < n; i++){
        dij_path[i] = i;
    }
    
    
    for(int i = 0; i < n; i++){
        int u = -1;
        int temp_min = max_init;
        for(int j = 0; j < n; j++){
            if(!dij_visit[j] && dij_dis[j] < temp_min){
                u = j;
                temp_min = dij_dis[j];
            }
        }
        if(u == -1){

            return;
        }
        dij_visit[u] = true;
        for(int j = 0; j < n; j++){ //launch优化
            if(!dij_visit[j] && graph_length[u][j] != max_init){
                if(dij_dis[u] + graph_length[u][j] < dij_dis[j]){

                    dij_dis[j] = dij_dis[u] + graph_length[u][j];
                    dij_time[j] = dij_time[u] + graph_time[u][j];
                    dij_path[j] = u;


                }else if(dij_dis[u] + graph_length[u][j] == dij_dis[j] && dij_time[u] + graph_time[u][j] < dij_time[j])
                {
                    dij_time[j] = dij_time[u] + graph_time[u][j];
                    dij_path[j] = u;
                }
                

            }

        }


    }

}
int section_cnt[501];
void time_dijkstra(int start){
    for(int i = 0; i < n; i++){
        dij_path[i] = i;
    }
    fill(dij_time, dij_time + 501, max_init);
    fill(section_cnt, section_cnt + 501, 0);
    fill(dij_visit, dij_visit + 501, false);
    dij_time[start] = 0;
    for(int i = 0; i < n; i++){
        int u = -1;
        int min = max_init;
        for(int j = 0; j < n; j++){
            if(!dij_visit[j] && dij_time[j] < min){
                u = j;
                min = dij_time[j];
            }
        }
        if(u == -1){

            return;
        }
        dij_visit[u] = true;
        for(int j = 0; j < n; j++){ //launch优化
            if(!dij_visit[j] && graph_time[u][j] != max_init){
                if(dij_time[u] + graph_time[u][j] < dij_time[j]){

                    dij_time[j] = dij_time[u] + graph_time[u][j];
                    dij_path[j] = u;
                    section_cnt[j] = section_cnt[u] + 1;


                }else if(dij_time[u] + graph_time[u][j] == dij_time[j] && section_cnt[u] + 1 < section_cnt[j])
                {
                    
                    section_cnt[j] = section_cnt[u] + 1;
                    dij_path[j] = u;
                }
                

            }

        }


    }

}
int main(){

    
    cin >> n >> m;
    vec.resize(n);
    fill(graph_length[0], graph_length[0] + 501 * 501, max_init);
    fill(graph_time[0], graph_time[0] + 501 * 501, max_init);
    for(int i = 0; i < m; i++){
        
        int v1, v2, one_way, length, time;
        scanf("%d %d %d %d %d", &v1, &v2, &one_way, &length, &time);
        graph_length[v1][v2] = length;
        graph_time[v1][v2] = time;
        vec[v1].push_back(v2);
        if(!one_way){
            vec[v2].push_back(v1);
            graph_time[v2][v1] = time;
            graph_length[v2][v1] = length;
        }
            
    }  

    int in_start, in_end;

    scanf("%d %d", &in_start, &in_end);
    dis_dijkstra(in_start);
    
 
    vector<int> vec_time_out;
    vector<int> vec_dis_out;
    int x = in_end;
    while (x != dij_path[x])
    {
        vec_dis_out.push_back(dij_path[x]);
        x = dij_path[x];
    }
    time_dijkstra(in_start);
    x = in_end;
    while (x != dij_path[x])
    {
        vec_time_out.push_back(dij_path[x]);
        x = dij_path[x];
    }
    // dfs(in_start, in_end, 0, 0);
    // Distance = 6: 3 -> 4 -> 8 -> 5
    // Time = 3: 3 -> 1 -> 5
    // Distance = 3; Time = 4: 3 -> 2 -> 5


    if(vec_dis_out == vec_time_out){

        printf("Distance = %d; Time = %d: ", dij_dis[in_end], dij_time[in_end]);
        for(int i = vec_dis_out.size() - 1; i >= 0 ; i--){
            printf("%d -> ", vec_dis_out[i]);
        }
        
        printf("%d\n", in_end);

    }else
    {
        printf("Distance = %d: ", dij_dis[in_end]);
        for(int i = vec_dis_out.size() - 1; i >= 0 ; i--){
            printf("%d -> ", vec_dis_out[i]);
        }
        
        printf("%d\n", in_end);
        printf("Time = %d: ", dij_time[in_end]);
        for(int i = vec_time_out.size() - 1; i >= 0 ; i--){
            printf("%d -> ", vec_time_out[i]);
        }
        
        printf("%d\n", in_end);

    }

        // if(time_path == dis_path){

    //     printf("Distance = %d; Time = %d: ", min_dis, min_time);
    //     printf("%d", in_start);
    //     for(int i = 0; i < time_path.size(); i++){
    //         printf(" -> %d", time_path[i]);
    //     }
    //     printf("\n");

    // }else
    // {
    //     printf("Distance = %d: ", min_dis);
    //     printf("%d", in_start);
    //     for(int i = 0; i < dis_path.size(); i++){
    //         printf(" -> %d", dis_path[i]);
    //     }
    //     printf("\n");
    //     printf("Time = %d: ", min_time);
    //     printf("%d", in_start);
    //     for(int i = 0; i < time_path.size(); i++){
    //         printf(" -> %d", time_path[i]);
    //     }
    //     printf("\n");

    // }
    
    


    return 0;
}

 

基于数据驱动的 Koopman 算子的递归神经网络模型线性化,用于纳米定位系统的预测控制研究(Matlab代码实现)内容概要:本文围绕“基于数据驱动的 Koopman 算子的递归神经网络模型线性化,用于纳米定位系统的预测控制研究”展开,提出了一种结合数据驱动方法与Koopman算子理论的递归神经网络(RNN)模型线性化方法,旨在提升纳米定位系统的预测控制精度与动态响应能力。研究通过构建数据驱动的线性化模型,克服了传统非线性系统建模复杂、计算开销大的问题,并在Matlab平台上实现了完整的算法仿真与验证,展示了该方法在高精度定位控制中的有效性与实用性。; 适合人群:具备一定自动化、控制理论或机器学习背景的科研人员与工程技术人员,尤其是从事精密定位、智能控制、非线性系统建模与预测控制相关领域的研究生与研究人员。; 使用场景及目标:①应用于纳米级精密定位系统(如原子力显微镜、半导体制造设备)中的高性能预测控制;②为复杂非线性系统的数据驱动建模与线性化提供新思路;③结合深度学习与经典控制理论,推动智能控制算法的实际落地。; 阅读建议:建议读者结合Matlab代码实现部,深入理解Koopman算子与RNN结合的建模范式,重点关注数据预处理、模型训练与控制系统集成等关键环节,并可通过替换实际系统数据进行迁移验证,以掌握该方法的核心思想与工程应用技巧。
ArcGIS 中的 **Online Map** 功能是指通过 **ArcGIS Online** 提供的基于云的地图服务,用户可以访问、创建、共享和管理地图、图层、数据以及地理空间资源。该功能整合了全球范围内的底图、地图数据、应用程序、可配置模板和开发工具,支持用户构建和发布 Web 地图及地理信息应用[^1]。 ### 核心功能与特点 1. **丰富的底图与图层资源** ArcGIS Online 提供了多种底图选项,包括地形图、卫星影像、街道地图等,同时也支持用户通过在线服务(如高德地图、Wayback影像地图等)加载第三方图层[^2]。 2. **Web 地图创建与管理** 用户可以通过 ArcGIS Online 创建交互式 Web 地图,添加本地或在线数据图层,并进行样式配置、符号化设置和图层管理。地图可以保存在用户的组织中,并与团队共享或公开发布[^1]。 3. **集成故事地图(Story Maps)** 通过 ArcGIS StoryMaps,用户可以将地图与文本、图片、视频等内容结合,制作具有叙述性的可视化项目。该功能广泛应用于教育、宣传、灾害管理等领域。 4. **支持在线服务发布与调用** 用户可以发布地图服务、要素服务、影像服务等,并通过 REST API 或 Web 应用程序调用这些服务。开发者可以利用 ArcGIS API 构建定制化的 GIS 应用程序。 5. **协作与共享能力** ArcGIS Online 支持多用户协作,用户可以创建群组、共享内容,并设置权限控制。组织内的成员可以共同编辑地图、析数据和查看仪表板[^1]。 6. **跨平台与移动支持** 所有通过 Online Map 创建的地图和应用均可在桌面浏览器、移动设备和 ArcGIS 应用程序中访问,实现跨平台使用。 7. **扩展性与插件支持** 用户可以通过自定义模板、添加外部图层(如 TMS、WMS 等)来扩展地图内容。例如,在 ArcMap 中可以直接从 ArcGIS Online 添加图层,也可以手动配置第三方地图服务作为底图[^2][^3]。 ### 示例:添加在线底图(如高德地图)的配置方式 ```xml <TileLayer> <Name>高德地图</Name> <UrlTemplate>https://webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}</UrlTemplate> <SubDomains>1,2,3,4</SubDomains> </TileLayer> ``` 通过上述配置,可以将高德地图作为底图加载到 ArcGIS Online 或 ArcMap 中,实现多源数据的融合展示[^3]。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值