bzoj3538[Usaco2014 Open]Dueling GPS*
生活随笔
收集整理的這篇文章主要介紹了
bzoj3538[Usaco2014 Open]Dueling GPS*
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
bzoj3538[Usaco2014 Open]Dueling GPS
題意: 給你一個N個點的有向圖,設定初始位置為1,結束位置為n。有兩個GPS定位系統,分別認為經過邊i的時間為Pi,和Qi.每走一條邊的時候,如果一個系統認為走的這條邊不是它認為的最短路,就會受到警告一次。如果走的這條邊都不在兩個系統認為的最短路范圍內,就會受到2次警告。求最少需要受到多少次警告。n≤10000,邊數≤50000 題解: 分別按兩個GPS的邊權求最短路,然后枚舉每條邊,把該邊的邊權變為其警告數,然后再求一次最短路。判斷該邊是不是最短路的條件是是否dis[es[i].f]+es[i].w==dis[es[i].t]。 代碼: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <queue> 5 #define inc(i,j,k) for(int i=j;i<=k;i++) 6 #define maxn 10010 7 #define INF 0x3fffffff 8 using namespace std; 9 10 inline int read(){ 11 char ch=getchar(); int f=1,x=0; 12 while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();} 13 while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); 14 return f*x; 15 } 16 struct e{int f,t,w,n;}es[maxn*5]; int g[maxn],ess; 17 void pe(int f,int t,int w){es[++ess]=(e){f,t,w,g[f]}; g[f]=ess;} 18 int n,m,a[2][maxn*5],b[maxn*5],d[2][maxn]; queue<int>q; bool inq[maxn]; 19 void spfa(int s,int o){ 20 while(!q.empty())q.pop(); memset(inq,0,sizeof(inq)); inc(i,1,n)d[o][i]=INF; 21 q.push(s); inq[s]=1; d[o][s]=0; 22 while(!q.empty()){ 23 int x=q.front(); q.pop(); inq[x]=0; 24 for(int i=g[x];i;i=es[i].n)if(d[o][x]+es[i].w<d[o][es[i].t]){ 25 d[o][es[i].t]=d[o][x]+es[i].w; if(!inq[es[i].t])q.push(es[i].t),inq[es[i].t]=1; 26 } 27 } 28 } 29 int main(){ 30 n=read(); m=read(); inc(i,1,m){int x=read(),y=read(),z=read(); pe(y,x,z); a[0][i]=z; a[1][i]=read();} 31 spfa(n,0); inc(i,1,m)es[i].w=a[1][i]; spfa(n,1); 32 inc(i,1,m){inc(j,0,1)if(d[j][es[i].f]+a[j][i]>d[j][es[i].t])b[i]++; es[i].w=b[i];} 33 spfa(n,0); printf("%d",d[0][1]); return 0; 34 }?
20160909轉載于:https://www.cnblogs.com/YuanZiming/p/5876454.html
總結
以上是生活随笔為你收集整理的bzoj3538[Usaco2014 Open]Dueling GPS*的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AcWing861 二分图的最大匹配 匈
- 下一篇: 关于创建奇门自定义api接口流程备忘录