日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【洛谷P3106】[USACO14OPEN]GPS的决斗Dueling GPS's

發布時間:2025/3/20 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【洛谷P3106】[USACO14OPEN]GPS的决斗Dueling GPS's 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述

給你一個N個點的有向圖,可能有重邊.

有兩個GPS定位系統,分別認為經過邊i的時間為Pi,和Qi.

每走一條邊的時候,如果一個系統認為走的這條邊不是它認為的最短路,就會受到警告一次T T

兩個系統是分開警告的,就是說當走的這條邊都不在兩個系統認為的最短路范圍內,就會受到2次警告.

如果邊(u,v)不在u到n的最短路徑上,這條邊就受到一次警告,求從1到n最少受到多少次警告。

輸入輸出格式

輸入格式:

  • Line 1: The integers N and M.

Line i describes road i with four integers: A_i B_i P_i Q_i.

輸出格式:

  • Line 1: The minimum total number of complaints FJ can receive if he routes himself from his house to the farm optimally.

代碼

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace std; const int maxn=50000+5; inline void read(int &x){x=0; char ch=getchar();while(ch<'0'||ch>'9') ch=getchar();while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} } int n,m,tot,u[maxn],v[maxn],p[maxn],q[maxn]; int head[maxn],dis[4][maxn]; bool inq[maxn]; queue<int>Q; struct node{int next,to,c[4]; }e[maxn<<1]; inline void ins(int from,int to,int c1,int c2,int c3){e[++tot].next=head[from];e[tot].to=to; e[tot].c[1]=c1; e[tot].c[2]=c2; e[tot].c[3]=c3;head[from]=tot; } void spfa(int x,int k){Q.push(x); dis[k][x]=0; inq[x]=1;do{int u=Q.front(); Q.pop(); inq[u]=0;for(int i=head[u];i;i=e[i].next)if(dis[k][e[i].to]>dis[k][u]+e[i].c[k]){dis[k][e[i].to]=dis[k][u]+e[i].c[k];if(!inq[e[i].to]) Q.push(e[i].to),inq[e[i].to]=1;}}while(!Q.empty()); } int main(){read(n);read(m);for(int i=1;i<=m;++i){read(u[i]);read(v[i]);read(p[i]);read(q[i]);ins(v[i],u[i],p[i],q[i],0);}memset(dis,0x3f,sizeof(dis));spfa(n,1); spfa(n,2);tot=0; memset(head,0,sizeof(head));for(int i=1;i<=m;++i){int w=2;if(dis[1][u[i]]-dis[1][v[i]]==p[i]) --w;if(dis[2][u[i]]-dis[2][v[i]]==q[i]) --w;ins(u[i],v[i],0,0,w);}spfa(1,3);printf("%d\n",dis[3][n]);return 0; }

?

轉載于:https://www.cnblogs.com/huihao/p/7757991.html

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的【洛谷P3106】[USACO14OPEN]GPS的决斗Dueling GPS's的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。