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,枚举)的更多相关文章

  1. HDU 5636 Shortest Path 暴力

    Shortest Path 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5636 Description There is a path graph ...

  2. HDU 5636 Shortest Path

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5636 题解: 1.暴力枚举: #include<cmath> #include<c ...

  3. HDU 5636 Shortest Path 分治+搜索剪枝

    题意:bc round 74 分析(官方题解): 你可以选择分类讨论, 但是估计可能会写漏一些地方. 只要抽出新增边的端点作为关键点, 建立一个新图, 然后跑一遍floyd就好了. 复杂度大概O(6^ ...

  4. HDU 5636 Shortest Path(Floyd)

    题目链接  HDU5636 n个点,其中编号相邻的两个点之间都有一条长度为1的边,然后除此之外还有3条长度为1的边. m个询问,每次询问求两个点之前的最短路. 我们把这三条边的6个点两两算最短路, 然 ...

  5. hdu 3631 Shortest Path(Floyd)

    题目链接:pid=3631" style="font-size:18px">http://acm.hdu.edu.cn/showproblem.php?pid=36 ...

  6. HDU - 3631 Shortest Path(Floyd最短路)

    Shortest Path Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u SubmitStat ...

  7. 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 ...

  8. hdu 3631 Shortest Path

    floyd算法好像很奇妙的样子.可以做到每次加入一个点再以这个点为中间点去更新最短路,效率是n*n. #include<cstdio> #include<cstring> #i ...

  9. HDU 4479 Shortest path 带限制最短路

    题意:给定一个图,求从1到N的递增边权的最短路. 解法:类似于bellman-ford思想,将所有的边先按照权值排一个序,然后依次将边加入进去更新,每条边只更新一次,为了保证得到的路径是边权递增的,每 ...

随机推荐

  1. hibernate 之 sql查询

    如果用hibernate执行原生sql进行数据查询可以调用 SQLQuery query = getSession().createSQLQuery(sql); 然后再执行 query.list() ...

  2. Symbol.iterator的理解

    https://blog.csdn.net/margin_0px/article/details/82971545

  3. selenium+phantomjs渲染网页

    from selenium import webdriverfrom selenium.webdriver.common.desired_capabilities import DesiredCapa ...

  4. C++ 关键字——friend【转载】

    转载自: http://www.cnblogs.com/CBDoctor/archive/2012/02/04/2337733.html 友元是指: 采用类的机制后实现了数据的隐藏与封装,类的数据成员 ...

  5. http 返回码 405 解决方案之一

    今天做网络请求数据的时候遇到返回码405,当时就傻了~~ 故事是这样的-- 我用post请求访问一个url,服务端数据是一个json的txt文件,理论上直接访问,返回json,然后解析就没事了,可是今 ...

  6. 在netbeans下使用调试PHP的插件XdeBug

    本人的开发环境: wamp最新官网wampserver2.2d-x32版. 下载点:http://nchc.dl.sourceforge.net/project/wampserver/WampServ ...

  7. Ldap 漏洞

    0x00 Ldap安装 官网地址:https://www.userbooster.de/en/download/openldap-for-windows.aspx 在win2008上安装,一路Next ...

  8. [Ubuntu] geoip-bin 程序包 - 查询 IP 归属地

    简述:在Linux命令行下查询IP归属地. 对Ubuntu/Debian系统,使用APT命令进行安装: $ sudo apt-get install geoip-bin 该包由MaxMind提供,它同 ...

  9. ScaleType属性

    FIT_CENTER 把原图按照比例放大缩小到ImageView的高度,显示在ImageView的center(中部/居中显示). 1   2 CENTER_CROP 会拉伸图片以原图填满ImageV ...

  10. 【摘抄】C++程序员练级攻略

    摘抄自互联网文章 作为C++程序员,或者说程序员一定要提升自己: 专访李运华:程序员如何在技术上提升自己-CSDN.NET专访徐宜生:坚决不做代码搬运工!-CSDN.NET 上面两个文章我觉得都不错. ...