zoukankan      html  css  js  c++  java
  • POJ 2253 floyd思想

    题意:求两块石头之间的青蛙的距离,即:起点到终点所有路径中最大跳跃距离的最小值

    思路:可以用floyd来求解

    floyd变形为dis[i][j]=MIN(dis[i][j],MAX(dis[i][k],dis[k][j]));

    View Code
      1 // I'm the Topcoder
      2 //C
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <string.h>
      6 #include <ctype.h>
      7 #include <math.h>
      8 #include <time.h>
      9 //C++
     10 #include <iostream>
     11 #include <algorithm>
     12 #include <cstdio>
     13 #include <cstdlib>
     14 #include <cmath>
     15 #include <cstring>
     16 #include <cctype>
     17 #include <stack>
     18 #include <string>
     19 #include <list>
     20 #include <queue>
     21 #include <map>
     22 #include <vector>
     23 #include <deque>
     24 #include <set>
     25 using namespace std;
     26 
     27 //*************************OUTPUT*************************
     28 #ifdef WIN32
     29 #define INT64 "%I64d"
     30 #define UINT64 "%I64u"
     31 #else
     32 #define INT64 "%lld"
     33 #define UINT64 "%llu"
     34 #endif
     35 
     36 //**************************CONSTANT***********************
     37 #define INF 0x3f3f3f3f
     38 #define eps 1e-8
     39 #define PI acos(-1.)
     40 #define PI2 asin (1.);
     41 typedef long long LL;
     42 //typedef __int64 LL;   //codeforces
     43 typedef unsigned int ui;
     44 typedef unsigned long long ui64;
     45 #define MP make_pair
     46 typedef vector<int> VI;
     47 typedef pair<int, int> PII;
     48 #define pb push_back
     49 #define mp make_pair
     50 
     51 //***************************SENTENCE************************
     52 #define CL(a,b) memset (a, b, sizeof (a))
     53 #define sqr(a,b) sqrt ((double)(a)*(a) + (double)(b)*(b))
     54 #define sqr3(a,b,c) sqrt((double)(a)*(a) + (double)(b)*(b) + (double)(c)*(c))
     55 
     56 //****************************FUNCTION************************
     57 template <typename T> double DIS(T va, T vb) { return sqr(va.x - vb.x, va.y - vb.y); }
     58 template <class T> inline T INTEGER_LEN(T v) { int len = 1; while (v /= 10) ++len; return len; }
     59 template <typename T> inline T square(T va, T vb) { return va * va + vb * vb; }
     60 
     61 // aply for the memory of the stack
     62 //#pragma comment (linker, "/STACK:1024000000,1024000000")
     63 //end
     64 
     65 const int maxn = 200+10;
     66 struct node{
     67     double x;
     68     double y;
     69 };
     70 node edge[maxn];
     71 int n;
     72 double dis[maxn][maxn];
     73 double juli(node a,node b){
     74     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
     75 }
     76 
     77 
     78 void floyd(){
     79     for(int k=0;k<n;k++){
     80         for(int i=0;i<n;i++){
     81             for(int j=0;j<n;j++){
     82                 dis[i][j]=min(dis[i][j],max(dis[i][k],dis[k][j]));
     83             }
     84         }
     85     }
     86 }
     87 
     88 int main(){
     89     //int n;
     90     int kase=0;
     91     while(scanf("%d",&n)!=EOF){
     92         if(n==0 )  break;
     93         for(int i=0;i<n;i++){
     94             scanf("%lf%lf",&edge[i].x,&edge[i].y);
     95         }
     96         for(int i=0;i<n;i++){
     97             for(int j=0;j<n;j++){
     98                 dis[i][j]=juli(edge[i],edge[j]);
     99             }
    100         }
    101         floyd();
    102         printf("Scenario #%d\n",++kase);
    103         printf("Frog Distance = %.3lf\n\n",dis[0][1]);
    104     }
    105     return 0;
    106 }
  • 相关阅读:
    layui 动态设置radio选中
    C# ling 查询 in 用法
    sql 去除小数点后面无效的0
    VUE 全局变量申明和取值
    SQL 逗号分隔将一行拆成多行
    devexpress 延长试用期 licenses.licx
    BugkuCTF-WEB4
    一招破解网页复制+网页上如何实现禁止复制粘贴
    JS的函数
    JS的数组
  • 原文地址:https://www.cnblogs.com/lanjiangzhou/p/2979959.html
Copyright © 2011-2022 走看看