P3106 [USACO14OPEN]GPS的决斗Dueling GPS's

题目描述

Farmer John has recently purchased a new car online, but in his haste he accidentally clicked the "Submit" button twice when selecting extra features for the car, and as a result the car ended up equipped with two GPS navigation systems! Even worse, the two systems often make conflicting decisions about the route that FJ should take.

The map of the region in which FJ lives consists of N intersections (2 <= N <= 10,000) and M directional roads (1 <= M <= 50,000). Road i connects intersections A_i (1 <= A_i <= N) and B_i (1 <= B_i <= N). Multiple roads could connect the same pair of intersections, and a bi-directional road (one permitting two-way travel) is represented by two separate directional roads in opposite orientations. FJ's house is located at intersection 1, and his farm is located at intersection N. It is possible to reach the farm from his house by traveling along a series of directional roads.

Both GPS units are using the same underlying map as described above; however, they have different notions for the travel time along each road. Road i takes P_i units of time to traverse according to the first GPS unit, and Q_i units of time to traverse according to the second unit (each travel time is an integer in the range 1..100,000).

FJ wants to travel from his house to the farm. However, each GPS unit complains loudly any time FJ follows a road (say, from intersection X to intersection Y) that the GPS unit believes not to be part of a shortest route from X to the farm (it is even possible that both GPS units can complain, if FJ takes a road that neither unit likes).

Please help FJ determine the minimum possible number of total complaints he can receive if he chooses his route appropriately. If both GPS units complain when FJ follows a road, this counts as +2 towards the total.

给你一个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.

输入输出样例

输入样例#1:

5 7
3 4 7 1
1 3 2 20
1 4 17 18
4 5 25 3
1 2 10 1
3 5 4 14
2 4 6 5
输出样例#1:

1

说明

There are 5 intersections and 7 directional roads. The first road connects from intersection 3 to intersection 4; the first GPS thinks this road takes 7 units of time to traverse, and the second GPS thinks it takes 1 unit of time, etc.

If FJ follows the path 1 -> 2 -> 4 -> 5, then the first GPS complains on the 1 -> 2 road (it would prefer the 1 -> 3 road instead). However, for the rest of the route 2 -> 4 -> 5, both GPSs are happy, since this is a shortest route from 2 to 5 according to each GPS.

啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊!!!!!!!!!!!!!!

挺了四天的题目终于过了~~~~~~~~~~~~

题意:
给你一个N个点的有向图,设定初始位置为1,结束位置为n。有两个GPS定位系统,分别认为经过边i的时间为Pi,和Qi.每走一条边的时候,如果一个系统认为走的这条边不是它认为的最短路,就会受到警告一次。如果走的这条边都不在两个系统认为的最短路范围内,就会受到2次警告。求最少需要受到多少次警告。n≤10000,边数≤50000
 #include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
using namespace std;
#define maxn 100010
#define MAXN 100010
#define mse(a,x) memset(a,x,sizeof(a));
queue<int>q;
int n,m,tot,ans,u[MAXN],v[MAXN],value1[MAXN];
int value2[MAXN],dis_1[],dis_2[];
int dis[maxn],head[maxn],link[maxn];
struct Edge{
int to,next,w_one,w_two;
}e[maxn],ee[maxn];
inline int read(){
int x=,f=;
char ch=getchar();
while(ch<'' || ch >''){
if (ch == '-')f=-;
ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
void SPFA_First(){
bool exist[maxn];
while(!q.empty())q.pop();
mse(dis_1,0x3f);mse(exist,false);
dis_1[n]=;q.push(n);exist[n]=true;
while(!q.empty()){
int p=q.front();q.pop();exist[p]=false;
for(int i=head[p];i;i=e[i].next){
int v=e[i].to;
if(dis_1[v]>dis_1[p]+e[i].w_one){
dis_1[v]=dis_1[p]+e[i].w_one;
if(!exist[v]){
q.push(v);exist[v]=true;
}
}
}
}
}
void SPFA_Second(){
bool exist[maxn];
while(!q.empty())q.pop();
mse(dis_2,0x3f);mse(exist,false);
dis_2[n]=;q.push(n);exist[n]=true;
while(!q.empty()){
int p=q.front();q.pop();exist[p]=false;
for(int i=head[p];i;i=e[i].next){
int v=e[i].to;
if(dis_2[v]>dis_2[p]+e[i].w_two){
dis_2[v]=dis_2[p]+e[i].w_two;
if(!exist[v]){
q.push(v);exist[v]=true;
}
}
}
}
} void Add_Edge(int u,int v,int w1,int w2){
e[++tot].to=v;e[tot].w_one=w1;e[tot].w_two=w2;
e[tot].next=head[u];head[u]=tot;
}
void SPFA_Third(){
bool exist[maxn];
while(!q.empty())q.pop();
mse(exist,false);mse(dis,0x3f);
dis[]=;exist[]=;q.push();
while(!q.empty()){
int now=q.front();q.pop();exist[now]=false;
for (int i=link[now];i;i=ee[i].next) {
if (dis[now]+ee[i].w_one<dis[ee[i].to]){
dis[ee[i].to]=dis[now]+ee[i].w_one;
if (!exist[ee[i].to]) {
q.push(ee[i].to);
exist[e[i].to]=;
}
}
}
}
}
int main()
{
n=read();m=read();
for(int i=;i<=m;i++){
u[i]=read();v[i]=read();
value1[i]=read();value2[i]=read();
Add_Edge(v[i],u[i],value1[i],value2[i]);
// 注意这里是 建的 反边
}
SPFA_First();
SPFA_Second();
for(int i=;i<=m;i++){
ee[i].to=v[i];ee[i].next=link[u[i]];
link[u[i]]=i;
if(dis_1[v[i]]+value1[i]>dis_1[u[i]])
ee[i].w_one++;
if(dis_2[v[i]]+value2[i]>dis_2[u[i]])
ee[i].w_one++;
}
SPFA_Third();
printf("%d",dis[n]);
return ;
}

终于可以骄傲的删掉那篇 待解决

BZOJ 3538 == 洛谷 P3106 [USACO14OPEN]GPS的决斗Dueling GPS's的更多相关文章

  1. Luogu P3106 [USACO14OPEN]GPS的决斗Dueling GPS's(最短路)

    P3106 [USACO14OPEN]GPS的决斗Dueling GPS's 题意 题目描述 Farmer John has recently purchased a new car online, ...

  2. 洛谷 3106 [USACO14OPEN]GPS的决斗Dueling GPS's 3720 [AHOI2017初中组]guide

    [题解] 这两道题是完全一样的. 思路其实很简单,对于两种边权分别建反向图跑dijkstra. 如果某条边在某一种边权的图中不是最短路上的边,就把它的cnt加上1.(这样每条边的cnt是0或1或2,代 ...

  3. 2018.07.22 洛谷P3106 GPS的决斗Dueling GPS's(最短路)

    传送门 图论模拟题. 这题直接写3个(可以压成一个)spfa" role="presentation" style="position: relative;&q ...

  4. [USACO14OPEN]GPS的决斗Dueling GPS's

    题目概况 题目描述 给你一个\(N\)个点的有向图,可能有重边. 有两个\(GPS\)定位系统,分别认为经过边\(i\)的时间为\(P_i\),和\(Q_i\). 每走一条边的时候,如果一个系统认为走 ...

  5. [BZOJ 3039&洛谷P4147]玉蟾宫 题解(单调栈)

    [BZOJ 3039&洛谷P4147]玉蟾宫 Description 有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地. ...

  6. bzoj 4816: 洛谷 P3704: [SDOI2017]数字表格

    洛谷很早以前就写过了,今天交到bzoj发现TLE了. 检查了一下发现自己复杂度是错的. 题目传送门:洛谷P3704. 题意简述: 求 \(\prod_{i=1}^{N}\prod_{j=1}^{M}F ...

  7. bzoj 1014: 洛谷 P4036: [JSOI2008]火星人

    题目传送门:洛谷P4036. 题意简述: 有一个字符串,支持插入字符,修改字符. 每次需要查询两个后缀的LCP长度. 最终字符串长度\(\le 100,\!000\),修改和询问的总个数\(\le 1 ...

  8. bzoj 3680(洛谷1337) 吊打XXX——模拟退火

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3680 https://www.luogu.org/problemnew/show/P1337 ...

  9. bzoj 4592(洛谷 4344) [Shoi2015]脑洞治疗仪——线段树上二分

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4592 1操作就是用线段树来二分找到第一个有 k 个0的位置. 在洛谷上A了,与暴力和网上题解 ...

随机推荐

  1. zabbix监控系统时间的问题

    分类: 监控 2013-03-19 21:40:11   发现zabbix监控系统时间的一个问题!zabbix监控系统时间用的key是system.localtime,返回当前的系统时间,而配置tig ...

  2. java实现单链表归并算法

    public class LinkMergeSort {static int number=0;public static void main(String[] args) {int[] a = {1 ...

  3. JS控制台的使用

    1.快捷键F12可直接进入控制台(或者单机右键->检查)用于bug调试 2.控制台如图: Elements:表示所有的js元素 Console:常用的有如下几个功能: ①console.log: ...

  4. 新装NGINX重启,出现错误 nginx: [error] open() "/usr/local/nginx/logs/nginx.pid"

    重装nginx出现,重启出现错误 ./nginx -s reload nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" ...

  5. 洛谷 P2279 [HNOI2003]消防局的设立

    题目描述 2020年,人类在火星上建立了一个庞大的基地群,总共有n个基地.起初为了节约材料,人类只修建了n-1条道路来连接这些基地,并且每两个基地都能够通过道路到达,所以所有的基地形成了一个巨大的树状 ...

  6. 水题:HDU1034-Candy Sharing Game

    解题心得: 1.我是用的模拟的算法直接模拟的每一轮的分配方法的得出的答案,看到有些大神使用的链表做的,好像链表才是这道题的镇长的做法吧. 题目: Candy Sharing Game Time Lim ...

  7. 运维Python面试题

    本章内容 1 osodjfoskjdofjsdjfjsdf 123 sdfdfadf   1 2 3 4 5 6 from django.db import models     class user ...

  8. loj2173 「FJOI2016」建筑师

    ref 真是道组合数学神题啊--第一次见第一类斯特林数-- #include <iostream> #include <cstdio> using namespace std; ...

  9. C#入门篇5-7:流程控制语句 continue语句

    #region continue语句 public class ContinueApp { public static void Fun1() { //标签打印显示1…30,若能被3整除则不打印. ; ...

  10. 设计模式之第16章-代理模式(Java实现)

    设计模式之第16章-代理模式(Java实现) “现在朋友圈真是太让人蛋疼了啊.”“怎么说?”“一堆代理,各种卖东西的,看着好烦人.”“哎,删了呗.”“都是朋友,哪里好意思删啊.”“这倒也是...哎,迫 ...