标签:des style blog http io color ar os for
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 26519 | Accepted: 8633 |
Description
Input
Output
Sample Input
2 0 0 3 4 3 17 4 19 4 18 5 0
Sample Output
Scenario #1 Frog Distance = 5.000 Scenario #2 Frog Distance = 1.414
二分最大距离 + 记忆化dfs一条可行路...
#include <iostream> #include <vector> #include <queue> #include <cmath> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; typedef long long LL; const int N = 210; const int inf = 1e9+7 ; const double eps = 1e-7; int n , m ; double dis[N][N] , x[N] , y[N]; inline double DIS( int a , int b ){ return sqrt((x[a]-x[b])*(x[a]-x[b]) + (y[a]-y[b])*(y[a]-y[b]));} bool vis[N] ; struct node { int v ; double w; node(){}; node( int a , double b ) { v =a , w = b; } }; vector<node>g[N]; bool tag ; void dfs( int u ,double DIS ) { if( vis[u] || tag ) return ; if( u == 2 ) { tag = true ; return ; } vis[u] = true ; for( int i = 0 ; i < g[u].size(); ++i ){ int v = g[u][i].v ; double w = g[u][i].w ; if( DIS + eps < w ) continue ; dfs( v , DIS ); } } bool test( double DIS ) { tag = false; memset( vis , false , sizeof vis ); dfs( 1, DIS ); if( tag ) return true; return false; } void run() { for( int i = 0 ; i <= n ; ++i ) g[i].clear() ; for( int i = 1 ; i <= n ; ++i ) cin >> x[i] >> y[i] ; for( int i = 1 ; i <= n ; ++i ){ for( int j = i + 1 ; j <= n ; ++j ){ double w = DIS( i , j ); g[i].push_back(node(j,w)); g[j].push_back(node(i,w)); } } double ans = 0 , l = 0.0 , r = DIS(1,2) + 10.0; while( l + eps <= r ){ double mid = (l+r) / 2.0 ; if( !test(mid) ) l = mid + eps ; else ans = mid , r = mid - eps ; } printf("%.3lf\n\n",ans); } int main() { #ifdef LOCAL freopen( "in.txt","r",stdin ); #endif // LOCAL ios::sync_with_stdio(false); int cas = 1 ; while( cin >> n && n ) cout << "Scenario #"<< cas++ <<endl << "Frog Distance = " , run(); }
标签:des style blog http io color ar os for
原文地址:http://www.cnblogs.com/hlmark/p/4069976.html