60分求调,悬关
查看原帖
60分求调,悬关
1072722
yywh楼主2024/4/9 22:21

60分求调,悬关

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

struct node {
    int x, y;
};


struct ed {
    node a[4];
    int t;
}city[500];


int n, s, t, a, b;
long double dis[1070][1070];

inline void add(int u, int v,long double w) {
    dis[u][v] = w;
}

inline bool vertical(node a,node b,node c) {
    if (((b.x-a.x)*(c.x-a.x)+(b.y-a.y)*(c.y-a.y))==0) return true;
    return false;
}

inline void f(ed &ci) {
    node* tmp = ci.a;
    if (vertical(tmp[0], tmp[1], tmp[2])) {
        ci.a[3].x = tmp[1].x + tmp[2].x - tmp[0].x;
        ci.a[3].y = tmp[1].y + tmp[2].y - tmp[0].y;
    }
    else if (vertical(tmp[1], tmp[0], tmp[2])) {
        ci.a[3].x = tmp[1].x + tmp[0].x - tmp[2].x;
        ci.a[3].y = tmp[1].y + tmp[0].y - tmp[2].y;
    }
    else {
        ci.a[3].x = tmp[1].x + tmp[0].x - tmp[2].x;
        ci.a[3].y = tmp[1].y + tmp[0].y - tmp[2].y;
    }   
}


inline long double PythagoreanTheorem(double a, double b) {
    return sqrt(a * a + b * b);
}


int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n; 
    for (int T = 1; T <= n; T++) {
        cin >> s >> t >> a >> b;
        for (int i = 1; i <= s; i++) {
            cin >> city[i].a[0].x >> city[i].a[0].y >> city[i].a[1].x >> city[i].a[1].y >> city[i].a[2].x >> city[i].a[2].y  >> city[i].t;
            f(city[i]);
        }
        for (int i = 0; i < 1070; i++) {
            for (int k = 0; k < 1070; k++) {
                dis[i][k] = 99999999999.9;
            }
        }
        for (int i = 1; i <= s; i++) {
            node* tmp = city[i].a;
            for (int k = 1; k <= 4; k++) {
                for (int j = 1; j <= 4; j++) {
                    if (k == j)continue;
                    add((i - 1) * 4 + k, (i - 1) * 4 + j, PythagoreanTheorem(tmp[k-1].x - tmp[j-1].x, tmp[k-1].y - tmp[j-1].y)*city[i].t);
                }
           }
        }
        for (int i = 1; i <= s; i++) {
            for (int k = 1; k <= 4; k++) {
                for (int j = 1; j <= s; j++) {
                    if (i == j)continue;
                    for (int m = 1; m <= 4; m++) {
                        add((i - 1) * 4 + k, (j - 1) * 4 + m, PythagoreanTheorem(city[i].a[k-1].x - city[j].a[m-1].x, city[i].a[k-1].y - city[j].a[m-1].y)*t);
                        /*if (((i - 1) * 4 + k) == 7 && ((j - 1) * 4 + m) == 12) {
                            cout << "debug:" << dis[7][12] << " " << city[i].a[k-1].x <<" "<< city[j].a[m-1].x << " " << city[i].a[k-1].y <<" "<< city[j].a[m-1].y << endl;
                        }*/
                    }
                }
            }
        }
        for (int i = 1; i <= s * 4; i++)dis[i][i] = 0;
        for (int k = 1; k <= s * 4; k++) {
            for (int i = 1; i <= s * 4; i++) {
                for (int j = 1; j <= s * 4; j++) {
                    dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
                    /*if (i == 7 && j == 12) {
                        cout << "debug:" << dis[i][j] << " " << dis[i][k] + dis[k][j] << " k=" << k << endl;
                    }*/
                }
            }
        }
        long double ans = 1145141919810.0;
        for (int i = (a - 1) * 4 + 1; i <= a * 4; i++) {
            for (int k = (b - 1) * 4 + 1; k <= b * 4; k++) {
                ans = min(ans, dis[i][k]);
                //cout << "debug("<<i<<" " << k<< "):" << dis[i][k] << endl;
            }
        }
        cout << fixed << setprecision(1) << ans << endl;
    }
    

    return 0;
}





2024/4/9 22:21
加载中...