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. 使用editorconfig配置你的编辑器

    摘要: 在团队开发中,统一的代码格式是必要的.但是不同开发人员使用的编辑工具可能不同,这样就造成代码的differ.今天给大家分享一个很好的方法来使不同的编辑器保持一样的风格. 不同的编辑器也有设置代 ...

  2. webdriver+expected_conditions二次封装

    结合这两种方法对代码做二次封装,可以提升脚本性能 例: #coding:utf-8 #封装元素方法from selenium import webdriverfrom selenium.webdriv ...

  3. GDAL------加载Shapefile文件

    代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...

  4. 爬虫 测试webmagic (一)

    目标:统计斗鱼(www.douyu.com)人数 思路: 1. 目录找到douyu播出的所有游戏 http://www.douyutv.com/directory 2. 借助 chrome 定位到每个 ...

  5. 1. Oracle安装部署文档

    一. 部署环境步骤 1.1 软件环境 操作系统:CentOS release 6.5oracle安装包:linux.x64_11gR2_database_1of1.zip:linux.x64_11gR ...

  6. Hbase 管理页面

    进入Hbase首页可以查看各种信息: http://192.168.23.128:16010/master-status

  7. linux CentOS 7 安装 RabbitMQ 3.6.3, Erlang 19.0

    1. 安装erlang 安装依赖环境 yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel unixO ...

  8. 119、 android:hardwareAccelerated="true"or"false"硬件加速的重要性

    每次做项目都会遇见一些特别简单的问题,但是又很费时间来让你解决的问题. 1.本身想实现一个简单的画廊效果,可是每次图片的显示都不能显示在正中的位置,真的很烦人,也花费了很长时间.最终还是知道了原因.解 ...

  9. 【Drools-开源业务规则引擎】入门实例(含源码)

    该实例转自:http://blog.csdn.net/quzishen/article/details/6163012 便于理解的应用实例1: 现在我们模拟一个应用场景:网站伴随业务产生而进行的积分发 ...

  10. python爬虫---->scrapy的使用(一)

    这里我们介绍一下python的分布式爬虫框架scrapy的安装以及使用.平庸这东西犹如白衬衣上的污痕,一旦染上便永远洗不掉,无可挽回. scrapy的安装使用 我的电脑环境是win10,64位的.py ...