74(2B)Shortest Path (hdu 5636) (Floyd)
Shortest Path
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 627 Accepted Submission(s): 204
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.
如果想做出这道题, 重要的是思路和知识的熟练掌握, Floyd模板并不难, 但怎么将它巧妙的用到了题中是值得思考的问题,还是自己掌握的不熟练, 一看别人的就懂, 但让自己写却毫无头绪
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
#include <iostream> using namespace std; #define MOD (1000000000+7) int main()
{
int T;
scanf("%d", &T); while(T--)
{
int n, m, i, j, k, l, r, u, v, a[10];
int dp[10][10];
long long res=0, len; scanf("%d%d", &n, &m); for(i=1; i<=6; i++)
scanf("%d", &a[i]); for(i=1; i<=6; i++) ///相当于对dp初始化
for(j=1; j<=6; j++)
dp[i][j] = abs(a[i]-a[j]); if(a[1]!=a[2]) dp[1][2] = dp[2][1] = 1; ///如果两点不相等的话就让两点的距离为1
if(a[3]!=a[4]) dp[3][4] = dp[4][3] = 1;
if(a[5]!=a[6]) dp[5][6] = dp[6][5] = 1; for(k=1; k<=6; k++)
for(i=1; i<=6; i++)
for(j=1; j<=6; j++)
dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]); for(i=1; i<=m; i++)
{
scanf("%d%d", &l, &r);
len = abs(l-r); for(u=1; u<=6; u++)
for(v=1; v<=6; v++)
len = min(len, (long long)(abs(a[u]-l)+dp[u][v]+abs(a[v]-r))); res = (res+len*i)%MOD;
} printf("%I64d\n", res); }
return 0;
}
74(2B)Shortest Path (hdu 5636) (Floyd)的更多相关文章
- HDU 5636 关键点的 floyd 最短路问题
Shortest Path Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- JAVA之单源最短路径(Single Source Shortest Path,SSSP问题)dijkstra算法求解
题目简介:给定一个带权有向图,再给定图中一个顶点(源点),求该点到其他所有点的最短距离,称为单源最短路径问题. 如下图,求点1到其他各点的最短距离 准备工作:以下为该题所需要用到的数据 int N; ...
- 单源最短距离 Single Source Shortest Path
单源最短距离_示例程序_图模型_用户指南_MaxCompute-阿里云 https://help.aliyun.com/document_detail/27907.html 单源最短距离 更新时间:2 ...
- HDU 4725 The Shortest Path in Nya Graph (最短路 )
This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just ...
- HDU 4725 The Shortest Path in Nya Graph(构图)
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- HDU 4725 The Shortest Path in Nya Graph (最短路)
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- HDU 4725 The Shortest Path in Nya Graph(最短路径)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)
Description This is a very easy problem, your task is just calculate el camino mas corto en un grafi ...
- hdu 4725 The Shortest Path in Nya Graph (最短路+建图)
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- hdu 3631 Shortest Path(Floyd)
题目链接:pid=3631" style="font-size:18px">http://acm.hdu.edu.cn/showproblem.php?pid=36 ...
随机推荐
- Jmeter常用脚本开发之FTP请求
1.没有FTP站点的,可以自己搭建一个FTP站点供测试使用,搭建步骤: l 安装IIS组件,控制面板—>程序和功能—>启用或关闭windows功能,勾选FTP服务器.IIS管理控制台,点 ...
- org.apache.commons.net.ftp
org.apache.commons.NET.ftp Class FTPClient类FTPClient java.lang.Object Java.lang.Object继承 org.apache. ...
- js 逻辑运算符
两个逻辑运算符的操作顺序在自己的脑海里一直理不清,用js做了个实验 <script type="text/javascript"> if(false && ...
- 解决 win 7 64 位 vs2010 调试silverlight项目无法加载,提示更新developer ,跟新报 消息 ID: 1517 已安装了 Silverlight 的 64 位版本
出现上面的问题是我们安装的silverlight的版本和系统给的silverlight下载的版本冲突, 解决的方法是,首先卸载Silverlight runtime(也就是默认的silverlight ...
- poj 3624 && hdu 2955(背包入门)
http://poj.org/problem?id=3624 背包中最基础的01背包,大意是有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].求解将哪些物品装入背包可使价值总 ...
- 使用spec文件语法创建一个rpm
How to create an RPM package/zh-hk < How to create an RPM package 此页面包含 Packaging:ScriptletSnippe ...
- 1.1 Java 的概述
[什么是java]:Java是一种可以撰写跨平台应用软件的面向对象的程序设计语言,是有SunMicrosystems公司于1995年5月推出的Java程序设计语言和Java平台(即JavaSE,Jav ...
- c#比delphi先进的地方
下面是一个例子: using System;namespace HelloWorld{ class Hello{ private static string DateDiff( ...
- sex在软件开发中的运用--SIX技术
开篇:省略xxx字 keyword:sex . female, male .SIX ,sex integer extention technolgolsl 前言: 对于sex字段的研究,国内,国际尚为 ...
- sleep()方法和yield()方法有什么区别?
两者都是Thread类的静态方法,定义如下 public static void sleep(long millis) throws InterruptedException public stati ...