• UVA 1347 Tour


    题意:按x从小到大给出n个点,要求一条从最左走到最右再回到最左的路径最小值 要求走过每个点

    Solution by Rujia,liu

    #include<iostream>
    #include<string>
    #include<cmath>
    #include<cstring>
    #include<vector>
    #include<map>
    #include<set>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<list>
    #include<sstream>
    #include<cstdio>
    #define INF 0x3f3f3f3f
    //const int maxn = 1e6 + 5;
    const double PI = acos(-1.0);
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    const int maxn = 50 + 5;
    double x[maxn], y[maxn], dist[maxn][maxn], d[maxn][maxn];
    
    int main() {
        int n;
        while (scanf("%d", &n) != EOF) {
            for (int i = 1; i <= n; i++) scanf("%lf%lf", &x[i], &y[i]);
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) dist[i][j] = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
            }
    
            for (int i = n - 1; i >= 2; i--) {
                for (int j = 1; j < i; j++) {
                    if (i == n - 1) d[i][j] = dist[i][n] + dist[j][n];
                    else d[i][j] = min(dist[i][i + 1] + d[i + 1][j], dist[j][i + 1] + dist[i + 1][i]);
                }
            }
            printf("%.2f\n", dist[1][2] + d[2][1]);
        }
        return 0;
    }
  • 相关阅读:
    React学习笔记(六)事件处理
    React学习笔记(五)State&声明周期
    学会装逼,你的人生可能会开挂
    Go指南
    JavaScript检测数据类型
    $.on()方法和addEventListener改变this指向
    JavaScript返回上一页
    js继承
    js原型二
    全局变量与局部变量
  • 原文地址:https://www.cnblogs.com/hznumqf/p/12336283.html
Copyright © 2020-2023  润新知