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;
}

最新文章

  1. delphi 文件删除,复制
  2. Android自带的theme
  3. Apache Spark源码走读之16 -- spark repl实现详解
  4. ActiveMQ持久化消息
  5. 为archlinux安装mplayer
  6. Lenovo Setup(安装程序)
  7. codeforces D. Queue 找规律+递推
  8. js运动 缓冲运动
  9. C语言学习笔记frist---输入两个数比较大小
  10. df -h统计的信息与du -sh不一致的原因(转)
  11. centos下一个bash: XXX: command not found解决方案
  12. svnclient本地化和异常处理
  13. mybatis like 的坑
  14. Java基础系列--集合之ArrayList
  15. macos 命令行安装 ipa
  16. java基础(十七)----- 浅谈Java中的深拷贝和浅拷贝 —— 面试必问
  17. c#使用dynamic关键字传输数据的用法
  18. $.ajax({})方法中的回调函数beforeSend,success,complete,error使用示例
  19. Spark1.0.0 源码编译和部署包生成
  20. oath2

热门文章

  1. CSS3制作美丽的3D表单
  2. IIS------项目配置到IIS后报500错误
  3. 雪花算法-snowflake
  4. [PyCharm] 设置自动启动时自动打开项目
  5. setTag,getTage复用
  6. iOS autoLayout总结
  7. TYAttributedLabel——简单,强大的iOS属性文本控件
  8. 原创:超简单!windows配置NDK开发环境使用JNI
  9. Bootstrap学习总结笔记(24)-- 基于BootstrapValidator的Form表单验证
  10. 《转》Python学习(16)-python异常