POJ 2253 Difference of Clustering

來源:互聯網
上載者:User

標籤:

題意:給出一堆點,求從起點到終點的所有通路中相鄰點的距離的最大值的最小值。(意思就是自己百度吧……)

 

解法:用相鄰點的最大值作為權值代替路徑的距離跑最短路或者最小產生樹。然後我寫了一個我以為是最佳化過的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 longusing 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\nFrog Distance = %.3lf\n\n", cse++, sqrt(ans));    }    return 0;}

  

POJ 2253 Difference of Clustering

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.