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. 读取properties的简单方法,使用@Configuration

    配置类代码如下 import org.springframework.beans.factory.annotation.Value; import org.springframework.contex ...

  2. 九、MySQL 创建数据表

    MySQL 创建数据表 创建MySQL数据表需要以下信息: 表名 表字段名 定义每个表字段 语法 以下为创建MySQL数据表的SQL通用语法: CREATE TABLE table_name (col ...

  3. 4-8 string

    1.常用的string模块 import string # 26个小写字母 print(string.ascii_lowercase) # abcdefghijklmnopqrstuvwxyz # 2 ...

  4. java util - json转换工具 gson

    需要 gson-2.7.jar 包 package cn.java.gson; import com.google.gson.JsonElement; import com.google.gson.J ...

  5. 网络编程协议(TCP和UDP协议,粘包问题)以及socketserver模块

    网络编程协议 1.osi七层模型 应用层  表示层  会话层  传输层  网络层  数据链路层  物理层 2.套接字 socket 有两类,一种基于文件类型,一种基于网络类型 3.Tcp和udp协议 ...

  6. Leetcode 515. 在每个树行中找最大值

    题目链接 https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/description/ 题目描述 您需要在二叉树的 ...

  7. n个人排队都不站在原来的位置

    一.题目描述 有n个人首先站成一排,请问,当n个人第二次再重新排列,每个人都不在原来的位置上,问有多少种站法.例如,原来有3个人,ABC,那么第二次每个人都不在原来的位置上有2种站法,BCA和CAB, ...

  8. Kubernetes配置Ceph RBD StorageClass

    1. 在Ceph上为Kubernetes创建一个存储池 # ceph osd pool create k8s 2. 创建k8s用户 # ceph auth get-or-create client.k ...

  9. Python 交互模式中 Delete/Backspace 键乱码问题

    进入 Python 交互模式,按下 Delete/Backspace 键,会出现 ^H 字符 解决方式: 1. 进到 Python 的Modules目录 [root@cyt-test Python-2 ...

  10. 常用Style

    有些输入框什么的,字数限制什么的style,ceb为我们写好了.我感觉,每个app的style都是很有用的一个东西. <?xml version="1.0" encoding ...