HDU 5636 Shortest Path(Floyed,枚举)
Shortest Path
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1146 Accepted Submission(s): 358
Problem Description
There is a path graph G=(V,E) with n vertices. Vertices are numbered from 1 to n and there is an edge with unit length between i and i+1 (1≤i
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
#define mod 1000000007
typedef long long int LL;
int dp[10][10];
int n,m;
long long int s;
int main()
{
int t;
scanf("%d",&t);
int a[10];
int x,y;
while(t--)
{
scanf("%d%d",&n,&m);
scanf("%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6]);
memset(dp,0,sizeof(dp));
for(int i=1;i<=6;i++)
{
for(int j=1;j<=6;j++)
{
dp[i][j]=abs(a[j]-a[i]);
}
}
dp[1][2]=1;dp[3][4]=1;dp[5][6]=1;
dp[2][1]=1;dp[4][3]=1;dp[6][5]=1;
for(int k=1;k<=6;k++)
{
for(int i=1;i<=6;i++)
{
for(int j=1;j<=6;j++)
{
dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
}
}
}
int res=0;
for(int i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
int ans=abs(y-x);
for(int i=1;i<=6;i++)
{
for(int j=1;j<=6;j++)
{
ans=min(ans,abs(x-a[i])+abs(y-a[j])+dp[i][j]);
}
}
// int num=i*ans%mod;
// res+=num;
// res%=mod;
(res+=(LL)i*ans%mod)%=mod;
}
printf("%d\n",res);
}
return 0;
}
HDU 5636 Shortest Path(Floyed,枚举)的更多相关文章
- HDU 5636 Shortest Path 暴力
Shortest Path 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5636 Description There is a path graph ...
- HDU 5636 Shortest Path
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5636 题解: 1.暴力枚举: #include<cmath> #include<c ...
- HDU 5636 Shortest Path 分治+搜索剪枝
题意:bc round 74 分析(官方题解): 你可以选择分类讨论, 但是估计可能会写漏一些地方. 只要抽出新增边的端点作为关键点, 建立一个新图, 然后跑一遍floyd就好了. 复杂度大概O(6^ ...
- HDU 5636 Shortest Path(Floyd)
题目链接 HDU5636 n个点,其中编号相邻的两个点之间都有一条长度为1的边,然后除此之外还有3条长度为1的边. m个询问,每次询问求两个点之前的最短路. 我们把这三条边的6个点两两算最短路, 然 ...
- hdu 3631 Shortest Path(Floyd)
题目链接:pid=3631" style="font-size:18px">http://acm.hdu.edu.cn/showproblem.php?pid=36 ...
- HDU - 3631 Shortest Path(Floyd最短路)
Shortest Path Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u SubmitStat ...
- 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 (J ...
- hdu 3631 Shortest Path
floyd算法好像很奇妙的样子.可以做到每次加入一个点再以这个点为中间点去更新最短路,效率是n*n. #include<cstdio> #include<cstring> #i ...
- HDU 4479 Shortest path 带限制最短路
题意:给定一个图,求从1到N的递增边权的最短路. 解法:类似于bellman-ford思想,将所有的边先按照权值排一个序,然后依次将边加入进去更新,每条边只更新一次,为了保证得到的路径是边权递增的,每 ...
随机推荐
- matlab矩阵内存预分配
matlab矩阵内存预分配就意味着,划定一个固定的内存块,各数据可直接按"行.列指数"存放到对应的元素中.若矩阵中不预配置内存.则随着"行.列指数"的变大.MA ...
- Hibernate_day01讲义_使用Hibernate完成对CRM系统中客户管理的DAO中的CRUD的操作
- WPF设置样式的几种方式
第一种方式是直接使用Setter来进行,可以对Background等进行设置. <Window.Resources> <Style TargetType="Button&q ...
- 查找被占用的端口的服务并kill掉
转自:http://blog.csdn.net/gsls200808/article/details/52456136 方法: C:\>netstat -ano|findstr 8000 TCP ...
- IIS中采用ISAPI-Rewrite防盗链
本规则支持白名单排除式防盗链,搜索引擎友好(不屏蔽),被盗链后的错误提示转向,支持各种文件类型,经作者亲验真的能用,第一时间在itmop.com原创发表,请继续往下阅读. 近来小站遇到了盗链问题,至使 ...
- 全屏加载loading显示的解决方法
step1:可以在网页里加一个div用来现实loading. <div id="loading"> <!--这里放你的loading时显示的动画或者文字--> ...
- SaltStack Grains 和 Pillar
Grains: (1) grains 是服务器的一系列粒子信息,也就是服务器的一系列物理,软件环境信息(2) grains 是 minion 启动时收集到的一些系统信息,比如操作系统版本.内核版本.C ...
- Flask中向前端传递或者接收Json文件的方法
1. 利用flask的request.form.get()方法 这一中方法主要利用flask的request.form.get方法,获得前端发送给后台的json文件 Python 端代码: @app. ...
- 页面调用Iframe中数据
<iframe src="html的路径(至于MVC中cshtml直接路径好像是不行的,得使用action进行请求出来的路径)" id="iframechild&q ...
- 虚拟机可以ping同宿主机,宿主机ping不通虚拟机
虚拟机里能ping同本机,而本机却ping不通虚拟机,或者虚拟机不能ping通本机,可能有如下原因: 如果是桥接模式,那么可能性1:虚拟机防火墙禁ping,请关闭虚拟机防火墙重试:root 状态下se ...