zoukankan      html  css  js  c++  java
  • 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
    ",res);
    
    
        }
        return 0;
    }
  • 相关阅读:
    设定cookie 获取cookie数据的转换
    cookie cookie的获取
    常见的请求方式 json字符串
    请求报文和响应报文
    http协议
    php分页查询 子查询
    MAC 地址为什么不需要全球唯一
    ceph分布式存储简介
    一文看懂为什么边缘计算是大势所趋
    真香!Windows 可直接运行 Linux 了
  • 原文地址:https://www.cnblogs.com/dacc123/p/8228790.html
Copyright © 2011-2022 走看看