zoukankan      html  css  js  c++  java
  • POJ 2253 Difference of Clustering

    题意:给出一堆点,求从起点到终点的所有通路中相邻点的距离的最大值的最小值。(意思就是自己百度吧……)

    解法:用相邻点的最大值作为权值代替路径的距离跑最短路或者最小生成树。然后我写了一个我以为是优化过的dijkstra但好像是prim的东西- -啊差不多啦……

    总之用优先队列维护权值进行广搜……然后交G++一直wa也不知道为啥……交了C++就过了……

    代码:

    #include<stdio.h>
    #include<iostream>
    #include<algorithm>
    #include<string>
    #include<string.h>
    #include<math.h>
    #include<limits.h>
    #include<time.h>
    #include<stdlib.h>
    #include<map>
    #include<queue>
    #include<set>
    #include<stack>
    #include<vector>
    #define LL long long
    using namespace std;
    struct node
    {
        int x, y;
    }p[205];
    struct node1
    {
        int point;
        int step;
        node1(int point, int step) : point(point), step(step) {}
        node1() {}
        bool operator < (const node1 &tmp) const
        {
            return step > tmp.step;
        }
    };
    int n;
    int caldis(node a, node b)
    {
        return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
    }
    int dis[205][205];
    vector <int> edge[205];
    bool vis[205];
    double bfs()
    {
        memset(vis, 0, sizeof vis);
        priority_queue <node1> q;
        q.push(node1(0, 0.0));
        while(!q.empty())
        {
            node1 tmp = q.top();
            q.pop();
            vis[tmp.point] = 1;
            if(tmp.point == 1) return tmp.step;
            for(int i = 0; i < edge[tmp.point].size(); i++)
            {
                if(!vis[edge[tmp.point][i]]) q.push(node1(edge[tmp.point][i], max(tmp.step, dis[tmp.point][edge[tmp.point][i]])));
            }
        }
    }
    int main()
    {
        int cse = 1;
        while(~scanf("%d", &n) && n)
        {
            for(int i = 0; i < n; i++)
                scanf("%d%d", &p[i].x, &p[i].y);
            int maxn = 0.0;
            for(int i = 0; i < n; i++)
                edge[i].clear();
            for(int i = 0; i < n; i++)
                for(int j = 0; j < n; j++)
                {
                    if(i == j) continue;
                    int tmp = caldis(p[i], p[j]);
                    edge[i].push_back(j);
                    dis[i][j] = tmp;
                }
            double ans = bfs();
            printf("Scenario #%d
    Frog Distance = %.3lf
    
    ", cse++, sqrt(ans));
        }
        return 0;
    }
    

      

  • 相关阅读:
    between…and…用法
    as用法
    as the saying goes 常言道
    share with用法
    know about用法
    *[topcoder]LCMSetEasy
    5生鲜超市(商品列表页功能,restful api基础以及vue项目结构介绍,drf的APIView、GenericView、viewsets和route)
    1生鲜超市(项目介绍)
    11生鲜超市(首页、商品数量、缓存和限速功能开发)
    Aplix助NEC/松下Linux手机平台建设
  • 原文地址:https://www.cnblogs.com/Apro/p/4843456.html
Copyright © 2011-2022 走看看