• [题解] uva 10369 Arctic Network(kruskal最小生成树)


    - 传送门 -

     https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1310

    # 10369 - Arctic Network Time limit: 3.000 seconds | [Root](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=0) | [![Submit](https://uva.onlinejudge.org/components/com_onlinejudge/images/button_submit.png "Submit")](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=submit_problem&problemid=1310&category=) [![Problem Stats](https://uva.onlinejudge.org/components/com_onlinejudge/images/button_stats.png "Problem Stats")](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=problem_stats&problemid=1310&category=) [![uDebug](https://uva.onlinejudge.org/components/com_onlinejudge/images/button_debug.png)](https://www.udebug.com/UVa/10369) [![Download as PDF](https://uva.onlinejudge.org/components/com_onlinejudge/images/button_pdf.png "Download as PDF")](https://uva.onlinejudge.org/external/103/10369.pdf) | ###(题面见pdf)
      ### - 题意 -  求最小生成树上第k大的边.   ### - 思路 -  难度大概在读题吧, 但我直接看题解的中文题意23333  可以把符合条件的第s大转化为第n-s小, kruskal到第n-s条边时直接得到答案.    细节见代码.   ### - 代码 - ```c++ #include #include #include #include using namespace std;

    typedef double db;
    const int N = 500 + 5;

    struct edge {
    int x, y;
    db v;
    }W[N*N];

    int F[N], X[N], Y[N];
    int cas, s, n, sz, cnt;

    bool cmp (edge a, edge b) { return a.v < b.v; }

    db distance(int i, int j) {
    return sqrt((X[i] - X[j]) * (X[i] - X[j]) * 1.0 + (Y[i] - Y[j]) * (Y[i] - Y[j]) * 1.0);
    }

    void init() {
    sz = cnt = 0;
    for (int i = 1; i <= n; ++i)
    F[i] = i;
    }

    int find(int x) { return x == F[x] ? x : F[x] = find(F[x]); }

    void kruskal() {
    for (int i = 1; i <= sz; ++i) {
    int fx = find(W[i].x), fy = find(W[i].y);
    if (fx == fy) continue;
    cnt++;
    if (cnt == s) {
    printf("%.2lf ", W[i].v);
    break;
    }
    F[fx] = fy;
    }
    }

    int main() {
    scanf("%d", &cas);
    for (int i = 1; i <= cas; ++i) {
    scanf("%d%d", &s, &n);
    if (s >= n) {
    printf("0.00 ");
    continue;
    }
    init();
    for (int j = 1; j <= n; ++j) {
    scanf("%d%d", &X[j], &Y[j]);
    for (int k = 1; k < j; ++k) {
    W[++sz].x = k; W[sz].y = j; W[sz].v = distance(k, j);
    }
    }
    s = n - s;
    sort(W + 1, W + sz + 1, cmp);
    kruskal();
    }
    return 0;
    }

  • 相关阅读:
    ConfigurationManager读取dll的配置文件
    计算机常用英语词汇
    Com与.Net互操作
    C#创建COM组件供VB,PB,Delphi调用
    程序员的自我修养
    .NET Remoting三种信道Http,Tcp,IPC和Web Service的访问速度比较(转)
    .NET Remoting与Socket、Webservice和WCF的比较及优势 (转)
    .NET Remoting 入门实例
    关于Assembly.LoadFrom和Assembly.LoadFile的区别
    大数据处理中必不可少的概念
  • 原文地址:https://www.cnblogs.com/Anding-16/p/7356165.html
Copyright © 2020-2023  润新知