樟树网站建设怎么用云虚拟主机建设网站
2025/12/22 15:50:35 网站建设 项目流程
樟树网站建设,怎么用云虚拟主机建设网站,樊城区建设局网站,硬件开发和软件开发区别2025年浙江大学计算机考研复试机试真题 2025年浙江大学计算机考研复试上机真题 历年浙江大学计算机考研复试上机真题 历年浙江大学计算机考研复试机试真题 更多学校题目开源地址#xff1a;https://gitcode.com/verticallimit1/noobdream N 诺 DreamJudge 题库#xff1…2025年浙江大学计算机考研复试机试真题2025年浙江大学计算机考研复试上机真题历年浙江大学计算机考研复试上机真题历年浙江大学计算机考研复试机试真题更多学校题目开源地址https://gitcode.com/verticallimit1/noobdreamN 诺 DreamJudge 题库输入 “学校名称” 即可筛选该校历年机试真题题目均在考纲范围内按难度自动排序。还可搭配《计算机考研机试攻略》刷题书中题目可通过题号直接在题库中查找。最短路径问题题目描述Time Limit: 1000 msMemory Limit: 256 mb给你n个点m条无向边每条边都有长度d和花费p给你起点s终点t要求输出起点到终点的最短距离及其花费如果最短距离有多条路线则输出花费最少的。输入输出格式输入描述:输入n,m点的编号是1~n,然后是m行每行4个数 a,b,d,p表示a和b之间有一条边且其长度为d花费为p。最后一行是两个数 s,t;起点s终点t。n和m为0时输入结束。 (1n1000, 0m100000, s ! t)输出描述:输出 一行有两个数 最短距离及其花费。输入输出样例输入样例#:3 2 1 2 5 6 2 3 4 5 1 3 0 0输出样例#:9 11代码一#include iostream#include vector#include algorithm#include iomanip#include set#include list#include string#include cmath#include stack#include map#include sstream#include queueusing namespace std;struct edge {int target;int length;int cost;};vectorintdist;vectorintcost;struct compare_dist {bool operator()(int a, int b) {return dist[a] dist[b];}};int main() {int n, m;while (cin n m) {if (n 0)break;mapint, vectoredgegraph;dist.resize(n 1); cost.resize(n 1);for (int i 1; i n; i) {dist[i] 1e9;cost[i] 1e9;}int node1, node2, length3, cost3;for (int i 0; i m; i) {cin node1 node2 length3 cost3;edge temp; temp.target node2; temp.cost cost3; temp.length length3;graph[node1].push_back(temp);temp.target node1;graph[node2].push_back(temp);}int s, t;cin s t;dist[s] 0; cost[s] 0;priority_queueint, vectorint, compare_distpq;pq.push(s);while (!pq.empty()) {int curr_node pq.top(); pq.pop();if (curr_node t)break;if(!graph[curr_node].empty()){for (auto v : graph[curr_node]) {int new_dist dist[curr_node] v.length;int new_cost cost[curr_node] v.cost;if (new_dist dist[v.target]) {dist[v.target] new_dist;cost[v.target] new_cost;pq.push(v.target);}else if (new_dist dist[v.target] new_cost cost[v.target]) {cost[v.target] new_cost;pq.push(v.target);}}}}cout dist[t] cost[t] endl;}return 0;}代码二#include iostream#include vector#include queueusing namespace std;struct Edge{int x,y,d,p;};struct Node{int x,d,p;friend bool operator (Node a, Node b){if(a.d b.d) return a.p b.p;return a.d b.d;}};const int maxN 1000;const int INF 0x3f3f3f3f;vectorint e[maxN5];vectorEdge edges;int dis[maxN5];int prices[maxN5];bool vis[maxN5];void addEdge(int a, int b, int d, int p){e[a].push_back(edges.size());edges.push_back({a,b,d,p});}int dijkstra(int s){dis[s] 0;prices[s] 0;priority_queueNode pq;pq.push({s,0,0});while(!pq.empty()){Node now pq.top();vis[now.x] true;pq.pop();for(int i 0; i e[now.x].size(); i){Edge edge edges[e[now.x][i]];if(dis[edge.y] dis[edge.x]edge.d|| dis[edge.y] dis[edge.x]edge.d prices[edge.y] prices[edge.x]edge.p){dis[edge.y] dis[edge.x]edge.d;prices[edge.y] prices[edge.x]edge.p;pq.push({edge.y, dis[edge.y],prices[edge.y]});}}}return 0;}int main() {int n,m;int a,b,d,p;int s, t;while(cin n m){if(n 0 m 0)break;for(int i 1; i n; i){dis[i] INF;prices[i] INF;}for(int i 0; i m; i){cin a b d p;addEdge(a,b,d,p);addEdge(b,a,d,p);}cin s t;dijkstra(s);cout dis[t] prices[t] endl;}return 0;}代码三#include bits/stdc.husing namespace std;const int INF 0x3f3f3f3f;int n,m;const int maxn 1001;struct edge {int u,v,w,p;edge(int _u, int _v, int _w,int _p) : u(_u), v(_v), w(_w), p(_p){}};vectoredge edges;vectorint G[maxn];//每个点的边在edges中的下标int vis[maxn];int dist[maxn];int path[maxn];int cost[maxn]; //从起点到某个点i的最少花费cost[i],但是是在距离最短优先情况下void spfa(int s) {queueint q;q.push(s);for(int i 0; i n; i) {dist[i] INF;}dist[s] 0;memset(cost,0,sizeof(cost));memset(vis,0,sizeof(vis));while(!q.empty()) {int u q.front();q.pop();vis[u] 0;for(int i 0; i G[u].size(); i) {edge e edges[G[u][i]];if(dist[e.v] dist[u] e.w) {dist[e.v] dist[u] e.w;path[e.v] u;cost[e.v] cost[u] e.p;if(vis[e.v] 0) {q.push(e.v);vis[e.v] 1;}}else if(dist[e.v] dist[u] e.w) {int new_cost cost[e.u] e.p;if(new_cost cost[e.v]) {cost[e.v] new_cost;path[e.v] u;}}}}}void addedge(int a, int b,int c, int d) {edges.push_back(edge(a,b,c,d));G[a].push_back(edges.size()-1);}void init() {for(int i 0; i n ;i) G[i].clear();edges.clear();}int main() {while(cinnm) {if(n 0 m 0) break;init();int a,b,c,d;for(int i0;im;i) {cinabcd;addedge(a,b,c,d);addedge(b,a,c,d);}int s,t;cin s t;spfa(s);cout dist[t] cost[t] endl;}}

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询