Advertisement
TLE

UVA - 534 - Frogger

TLE
Nov 12th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.77 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define pf(x) printf("%d",x)
  6. #define pfd(x,y) printf("%d %d",x,y)
  7. #define pfl(x) printf("%ld",x)
  8. #define nl printf("\n")
  9.  
  10. #define cs(x) printf("Case %d: ",x)
  11. #define csn(x) printf("Case %d:\n",x)
  12.  
  13. #define all(x) x.begin(),x.end()
  14. #define Find(x,n) find(all(x),n)
  15. #define pi acos(-1.0)
  16. #define i64 long long
  17. #define pb(x) push_back(x)
  18. #define mset(x,v) memset(x,v,sizeof(x))
  19. #define sc(n) scanf("%d",&n)
  20. #define scl(n) scanf("%ld",&n)
  21. #define scll(n) scanf("%lld",&n)
  22. #define scd(n,m) scanf("%d %d",&n,&m)
  23. #define scdl(n,m) scanf("%ld %ld",&n,&m)
  24. #define scdll(n,m) scanf("%lld %lld",&n,&m)
  25. #define filein freopen("in.txt","r",stdin)
  26. #define fileout freopen("my.txt","w",stdout)
  27. #define FOR(i,n) for(int i=0;i<n; i++)
  28. #define inf 20000000.0
  29.  
  30. bool isUpper(char ch){ if( ch>='A' && ch<='Z' ) return true; return false; }
  31. bool isLower(char ch){ if( ch>='a' && ch<='z') return true; return false;}
  32. bool isLetter(char ch){ if( ch>='A' && ch<='Z' || ch>='a' && ch<='z') return true; return false; }
  33. bool isDigit(char ch){ if( ch>='0' && ch<='9') return true; return false; }
  34. char toLower(char ch){ if (isUpper(ch)) return (ch+32); return ch; }
  35. char toUpper(char ch){ if (isLower(ch)) return (ch-32); return ch; }
  36.  
  37. template<class T>bool isEven(T a){ return (a%2==0);}
  38. template<class T>T sq(T a){ return a*a; }
  39. template<class T>T gcd(T a,T b){ return b==0 ? a : gcd(b,a%b); }
  40. template<class T>T lcm(T a,T b){ return (a/gcd(a,b))*b; }
  41. template<class T>bool isPrime(T n){ for(T i=2; i*i<=n; i++){ if(n%i==0) return false; } return true; }
  42. template<class T>T Pow(T n,T p) { T res=n; for(T i=1;i<p; i++){ res *= n; } return res; }
  43. template<class T>T Max(T n,T p) { if(n>=p) return n; return p; }
  44.  
  45. float g[210][210];
  46. vector<pair<int,int> >cor;
  47.  
  48. void floyd_warshall(int n){
  49.     for(int k=0;k<n; k++)
  50.         for(int i=0;i<n; i++)
  51.             for(int j=0;j<n; j++)
  52.                 if( g[i][j]>Max(g[i][k],g[k][j]) )
  53.                     g[i][j]=Max(g[i][k],g[k][j]);
  54.  
  55. }
  56.  
  57. void Set(int n){
  58.     for(int i=1;i<=n; i++)
  59.         for(int j=1;j<=n; j++)
  60.             g[i][j]=inf;
  61. }
  62.  
  63. float distance(int x1,int y1,int x2,int y2){
  64.     return (float)sqrt( sq(x2-x1)+sq(y2-y1)  );
  65. }
  66.  
  67. void init(int n){
  68.     for(int i=0;i<n;i++)
  69.         for(int j=0;j<n;j++)
  70.             if(i!=j)
  71.                 g[i][j]=distance(cor[i].first,cor[i].second,cor[j].first,cor[j].second);
  72. }
  73.  
  74. int main()
  75. {
  76.     //filein;
  77.  
  78.     int T=0,n;
  79.     while( sc(n)==1 && n ){
  80.         for(int i=0;i<n;i++){
  81.             int x,y;
  82.             scanf("%d %d",&x,&y);
  83.             cor.pb( make_pair(x,y) );
  84.         }
  85.         init(n);
  86.         floyd_warshall(n);
  87.         printf("Scenario #%d\nFrog Distance = %.3f\n\n",++T,g[0][1]);
  88.         cor.clear();
  89.     }
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement