HDU 5636 关键点的 floyd 最短路问题
Shortest Path
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 285 Accepted Submission(s): 92
You are given the graph and several queries about the shortest path between some pairs of vertices.
The first line contains two integer n and m (1≤n,m≤105) -- the number of vertices and the number of queries. The next line contains 6 integers a1,b1,a2,b2,a3,b3 (1≤a1,a2,a3,b1,b2,b3≤n), separated by a space, denoting the new added three edges are (a1,b1), (a2,b2), (a3,b3).
In the next m lines, each contains two integers si and ti (1≤si,ti≤n), denoting a query.
The sum of values of m in all test cases doesn't exceed 106.
10 2
2 4 5 7 8 10
1 5
3 1
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#define ll __int64
using namespace std;
ll t;
ll n,q;
ll a[];
ll dis[][];
int main()
{
scanf("%I64d",&t);
for(int i=;i<=t;i++)
{
memset(dis,,sizeof(dis));
scanf("%I64d %I64d",&n,&q);
scanf("%I64d %I64d %I64d %I64d %I64d %I64d",&a[],&a[],&a[],&a[],&a[],&a[]);
ll sum=;
for(int j=;j<=;j++)
for(int k=;k<=;k++)
{
dis[j][k]=abs(a[j]-a[k]);
}
dis[][]=;
dis[][]=;
dis[][]=;
dis[][]=;
dis[][]=;
dis[][]=;
for(int i=;i<=;i++)
for(int k=;k<=;k++)
for(int m=;m<=;m++)
{
if(dis[k][i]+dis[i][m]<dis[k][m])
dis[k][m]=dis[k][i]+dis[i][m];
}
for(int j=;j<=q;j++)
{
ll aa,bb,t;
scanf("%I64d %I64d",&aa,&bb);
if(aa>bb)
{
t=aa;
aa=bb;
bb=t;
}
ll ans=abs(bb-aa);
for(int k=;k<=;k++)
for(int m=;m<=;m++)
{
if(ans>abs(aa-a[k])+abs(bb-a[m])+dis[k][m])
ans=abs(aa-a[k])+abs(bb-a[m])+dis[k][m];
}
sum=(sum+j*ans)%;
}
printf("%I64d\n",sum);
}
return ;
}
HDU 5636 关键点的 floyd 最短路问题的更多相关文章
- 74(2B)Shortest Path (hdu 5636) (Floyd)
Shortest Path Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- hdu 5636 搜索 BestCoder Round #74 (div.2)
Shortest Path Accepts: 40 Submissions: 610 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: ...
- HDU 5636 Shortest Path(Floyd)
题目链接 HDU5636 n个点,其中编号相邻的两个点之间都有一条长度为1的边,然后除此之外还有3条长度为1的边. m个询问,每次询问求两个点之前的最短路. 我们把这三条边的6个点两两算最短路, 然 ...
- HDU 5636 Shortest Path
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5636 题解: 1.暴力枚举: #include<cmath> #include<c ...
- hdu 1874(Dijkstra + Floyd)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1874 畅通工程续 Time Limit: 3000/1000 MS (Java/Others) Me ...
- HDU 5636 Shortest Path 分治+搜索剪枝
题意:bc round 74 分析(官方题解): 你可以选择分类讨论, 但是估计可能会写漏一些地方. 只要抽出新增边的端点作为关键点, 建立一个新图, 然后跑一遍floyd就好了. 复杂度大概O(6^ ...
- HDU 2066 最短路floyd算法+优化
http://acm.hdu.edu.cn/showproblem.php?pid=206 题意 从任意一个邻居家出发 到达任意一个终点的 最小距离 解析 求多源最短路 我想到的是Floyd算法 但是 ...
- hdu 2066 ( 最短路) Floyd & Dijkstra & Spfa
http://acm.hdu.edu.cn/showproblem.php?pid=2066 今天复习了一下最短路和最小生成树,发现居然闹了个大笑话-----我居然一直写的是Floyd,但我自己一直以 ...
- HDU 1317 XYZZY(floyd+bellman_ford判环)
http://acm.hdu.edu.cn/showproblem.php?pid=1317 题意: 给出一个有向图,每到达一个点,都会加上或减去一些能量,我们要做的就是判断从1出发是否能到达n.初始 ...
随机推荐
- (C#)工厂方法模式
1.工厂方法模式 第一了一个用于创建对象的接口,让子类自己决定实例化哪一个类.工厂方法使一个类的实例化延迟到其子类. *工厂方法模式即克服了简单工厂模式违反开放-封闭原则的缺点,又保留了封装对象创建过 ...
- yii的学习笔记 基本结构 自用
Yii 学习笔记 W:YII是什么? Q:Yii 是一个基于组件的高性能 PHP 框架,用于快速开发大型 Web 应用.它使Web开发中的 可复用度最大化,可以显著提高你的Web应用开发速度.Yii ...
- python程序设计——函数设计与调用
一.函数定义与调用 def 函数名([参数列表]): '''注释''' 函数体 # 输出小于n的斐波那契数 >>def fib(n): a,b=1,1 while a < n: pr ...
- Pandas基础教程
pandas教程 更多地可以 参考教程 安装 pip install pandas pandas的类excel操作,超级方便: import pandas as pd dates = pd.date_ ...
- [leetcode-693-Binary Number with Alternating Bits]
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...
- HDU 3726 Graph and Queries(平衡二叉树)(2010 Asia Tianjin Regional Contest)
Description You are given an undirected graph with N vertexes and M edges. Every vertex in this grap ...
- 转:Linux 编译安装 Mysql5.7
http://broqiang.com/2017/04/18/Mysql-Install-5.7.18-Linux-Compile/ 原文 Linux 编译安装 Mysql5.7 Ubuntu 下快速 ...
- 11.24Daily Scrum(3)
人员 任务分配完成情况 明天任务分配 王皓南 实现网页上视频浏览的功能.研究相关的代码和功能.1002 数据库测试 申开亮 实现网页上视频浏览的功能.研究相关的代码和功能.1003 实现视频浏览的功能 ...
- eg_1
1. 编写一个程序,输出一个字符串中的大写英文字母个数,小写英文字母个数以及非英文字母个数. 第一种方法: public class Test { public static void main(St ...
- java — 排序算法
1.冒泡排序 比较相邻元素,如果第一个比第二个大,就交换位置,每一次交换,当前 package BubbleSort; public class Test { public static void m ...