• 【BZOJ】3394: [Usaco2009 Jan]Best Spot 最佳牧场(floyd)


    http://www.lydsy.com/JudgeOnline/problem.php?id=3394

    裸的floyd。。

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    using namespace std;
    #define rep(i, n) for(int i=0; i<(n); ++i)
    #define for1(i,a,n) for(int i=(a);i<=(n);++i)
    #define for2(i,a,n) for(int i=(a);i<(n);++i)
    #define for3(i,a,n) for(int i=(a);i>=(n);--i)
    #define for4(i,a,n) for(int i=(a);i>(n);--i)
    #define CC(i,a) memset(i,a,sizeof(i))
    #define read(a) a=getint()
    #define print(a) printf("%d", a)
    #define dbg(x) cout << (#x) << " = " << (x) << endl
    #define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
    #define printarr1(a, b) for1(_, 1, b) cout << a[_] << '	'; cout << endl
    inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
    inline const int max(const int &a, const int &b) { return a>b?a:b; }
    inline const int min(const int &a, const int &b) { return a<b?a:b; }
    
    const int N=505;
    int d[N][N], n, f, m, l[N];
    
    int main() {
    	read(n); read(f); read(m);
    	CC(d, 0x3f);
    	rep(i, f) read(l[i]);
    	rep(i, m) {
    		int u=getint(), v=getint(), w=getint();
    		d[u][v]=d[v][u]=w;
    	}
    	for1(i, 1, n) d[i][i]=0;
    	for1(k, 1, n) for1(i, 1, n) for1(j, 1, n) d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
    	int ans, mn=~0u>>1;
    	for1(i, 1, n) {
    		int sum=0;
    		rep(j, f) if(d[i][l[j]]!=0x3f3f3f3f) sum+=d[i][l[j]];
    		if(sum<mn) {
    			mn=sum;
    			ans=i;
    		}
    	}
    	print(ans);
    	return 0;
    }
    

    Description

    Input

    第1行输入三个整数P,F C.之后F行每行输入一个整数表示一个贝茜喜欢的牧场.之后C行每行输入三个整数ai,bi,Ti,描述一条路.

    Output

        一个整数,满足题目要求的最佳牧场.如果有多个答案,输出编号最小的

    Sample Input

    13 6 15
    11
    13
    10
    12
    8
    1
    2 4 3
    7 11 3
    10 11 1
    4 13 3
    9 10 3
    2 3 2
    3 5 4
    5 9 2
    6 7 6
    5 6 1
    1 2 4
    4 5 3
    11 12 3
    6 10 1
    7 8 7

    Sample Output

    10

    HINT

    Source

  • 相关阅读:
    算法训练 表达式计算
    基础练习 十六进制转十进制
    基础练习 十六进制转十进制
    基础练习 十六进制转十进制
    New ways to verify that Multipath TCP works through your network
    TCP的拥塞控制 (Tahoe Reno NewReno SACK)
    Multipath TCP Port for Android 4.1.2
    How to enable ping response in windows 7?
    NS3
    Multipath TCP Port for Android
  • 原文地址:https://www.cnblogs.com/iwtwiioi/p/4005620.html
Copyright © 2020-2023  润新知