POJ 2253 - Frogger (floyd)
A - Frogger
**Time Limit:**1000MS **Memory Limit:**65536KB 64bit IO Format:%I64d & %I64u
Submit Status
Description
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists' sunscreen, he wants to avoid swimming and instead reach her by jumping.
Unfortunately Fiona's stone is out of his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach her by a sequence of several small jumps.
To execute a given sequence of jumps, a frog's jump range obviously must be at least as long as the longest jump occuring in the sequence.
The frog distance (humans also call it minimax distance) between two stones therefore is defined as the minimum necessary jump range over all possible paths between the two stones.
You are given the coordinates of Freddy's stone, Fiona's stone and all other stones in the lake. Your job is to compute the frog distance between Freddy's and Fiona's stone.
Input
The input will contain one or more test cases. The first line of each test case will contain the number of stones n (2<=n<=200). The next n lines each contain two integers xi,yi (0 <= xi,yi <= 1000) representing the coordinates of stone #i. Stone #1 is Freddy's stone, stone #2 is Fiona's stone, the other n-2 stones are unoccupied. There's a blank line following each test case. Input is terminated by a value of zero (0) for n.
Output
For each test case, print a line saying "Scenario #x" and a line saying "Frog Distance = y" where x is replaced by the test case number (they are numbered from 1) and y is replaced by the appropriate real number, printed to three decimals. Put a blank line after each test case, even after the last one.
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<br></br><br></br> 裸的floyd...<br></br>注意格式<br></br>1A
<span style="color: #008080;"> 1</span> <span style="color: #008000;">/*</span><span style="color: #008000;">************************************************************************
</span><span style="color: #008080;"> 2</span> <span style="color: #008000;"> > File Name: poj/2253.cpp
</span><span style="color: #008080;"> 3</span> <span style="color: #008000;"> > Author: 111qqz
</span><span style="color: #008080;"> 4</span> <span style="color: #008000;"> > Email: rkz2013@126.com
</span><span style="color: #008080;"> 5</span> <span style="color: #008000;"> > Created Time: 2015年10月22日 星期四 22时52分18秒
</span><span style="color: #008080;"> 6</span> <span style="color: #008000;"> ***********************************************************************</span><span style="color: #008000;">*/</span>
<span style="color: #008080;"> 7</span>
<span style="color: #008080;"> 8</span> #include<iostream>
<span style="color: #008080;"> 9</span> #include<iomanip>
<span style="color: #008080;">10</span> #include<cstdio>
<span style="color: #008080;">11</span> #include<algorithm>
<span style="color: #008080;">12</span> #include<cmath>
<span style="color: #008080;">13</span> #include<cstring>
<span style="color: #008080;">14</span> #include<<span style="color: #0000ff;">string</span>>
<span style="color: #008080;">15</span> #include<map>
<span style="color: #008080;">16</span> #include<<span style="color: #0000ff;">set</span>>
<span style="color: #008080;">17</span> #include<queue>
<span style="color: #008080;">18</span> #include<vector>
<span style="color: #008080;">19</span> #include<stack>
<span style="color: #008080;">20</span> #include<cctype>
<span style="color: #008080;">21</span>
<span style="color: #008080;">22</span> <span style="color: #0000ff;">#define</span> yn hez111qqz
<span style="color: #008080;">23</span> <span style="color: #0000ff;">#define</span> j1 cute111qqz
<span style="color: #008080;">24</span> <span style="color: #0000ff;">#define</span> ms(a,x) memset(a,x,sizeof(a))
<span style="color: #008080;">25</span> <span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span><span style="color: #000000;"> std;
</span><span style="color: #008080;">26</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> dx4[<span style="color: #800080;">4</span>]={<span style="color: #800080;">1</span>,<span style="color: #800080;">0</span>,<span style="color: #800080;">0</span>,-<span style="color: #800080;">1</span><span style="color: #000000;">};
</span><span style="color: #008080;">27</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> dy4[<span style="color: #800080;">4</span>]={<span style="color: #800080;">0</span>,-<span style="color: #800080;">1</span>,<span style="color: #800080;">1</span>,<span style="color: #800080;">0</span><span style="color: #000000;">};
</span><span style="color: #008080;">28</span> typedef <span style="color: #0000ff;">long</span> <span style="color: #0000ff;">long</span><span style="color: #000000;"> LL;
</span><span style="color: #008080;">29</span> typedef <span style="color: #0000ff;">double</span><span style="color: #000000;"> DB;
</span><span style="color: #008080;">30</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> inf = <span style="color: #800080;">0x3f3f3f3f</span><span style="color: #000000;">;
</span><span style="color: #008080;">31</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> N=2E2+<span style="color: #800080;">7</span><span style="color: #000000;">;
</span><span style="color: #008080;">32</span> <span style="color: #0000ff;">double</span><span style="color: #000000;"> d[N][N];
</span><span style="color: #008080;">33</span> <span style="color: #0000ff;">double</span><span style="color: #000000;"> x[N],y[N];
</span><span style="color: #008080;">34</span> <span style="color: #0000ff;">int</span><span style="color: #000000;"> n;
</span><span style="color: #008080;">35</span>
<span style="color: #008080;">36</span>
<span style="color: #008080;">37</span> <span style="color: #0000ff;">double</span> dis( <span style="color: #0000ff;">int</span> a,<span style="color: #0000ff;">int</span><span style="color: #000000;"> b)
</span><span style="color: #008080;">38</span> <span style="color: #000000;">{
</span><span style="color: #008080;">39</span> <span style="color: #0000ff;">double</span><span style="color: #000000;"> res;
</span><span style="color: #008080;">40</span> res = (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-<span style="color: #000000;">y[b]);
</span><span style="color: #008080;">41</span> <span style="color: #0000ff;">return</span><span style="color: #000000;"> sqrt(res);
</span><span style="color: #008080;">42</span> <span style="color: #000000;">}
</span><span style="color: #008080;">43</span> <span style="color: #0000ff;">int</span><span style="color: #000000;"> main()
</span><span style="color: #008080;">44</span> <span style="color: #000000;">{
</span><span style="color: #008080;">45</span> <span style="color: #000000;"> #ifndef ONLINE_JUDGE
</span><span style="color: #008080;">46</span> freopen(<span style="color: #800000;">"</span><span style="color: #800000;">in.txt</span><span style="color: #800000;">"</span>,<span style="color: #800000;">"</span><span style="color: #800000;">r</span><span style="color: #800000;">"</span><span style="color: #000000;">,stdin);
</span><span style="color: #008080;">47</span> <span style="color: #0000ff;">#endif</span>
<span style="color: #008080;">48</span> <span style="color: #0000ff;">int</span> cas = <span style="color: #800080;">0</span><span style="color: #000000;"> ;
</span><span style="color: #008080;">49</span> <span style="color: #0000ff;">while</span> (scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%d</span><span style="color: #800000;">"</span>,&n;)!=EOF&&<span style="color: #000000;">n)
</span><span style="color: #008080;">50</span> <span style="color: #000000;"> {
</span><span style="color: #008080;">51</span> cas++<span style="color: #000000;">;
</span><span style="color: #008080;">52</span> printf(<span style="color: #800000;">"</span><span style="color: #800000;">Scenario #%dn</span><span style="color: #800000;">"</span><span style="color: #000000;">,cas);
</span><span style="color: #008080;">53</span> <span style="color: #0000ff;">for</span> ( <span style="color: #0000ff;">int</span> i = <span style="color: #800080;">0</span> ; i < n ; i++<span style="color: #000000;">)
</span><span style="color: #008080;">54</span> <span style="color: #0000ff;">for</span> ( <span style="color: #0000ff;">int</span> j = <span style="color: #800080;">0</span> ; j < n ; j++<span style="color: #000000;">)
</span><span style="color: #008080;">55</span> d[i][j] = <span style="color: #800080;">999999</span><span style="color: #000000;">;
</span><span style="color: #008080;">56</span> <span style="color: #0000ff;">for</span> ( <span style="color: #0000ff;">int</span> i = <span style="color: #800080;">0</span> ; i < n ; i++) scanf(<span style="color: #800000;">"</span><span style="color: #800000;">%lf %lf</span><span style="color: #800000;">"</span>,&x;[i],&<span style="color: #000000;">y[i]);
</span><span style="color: #008080;">57</span>
<span style="color: #008080;">58</span> <span style="color: #0000ff;">for</span> ( <span style="color: #0000ff;">int</span> i = <span style="color: #800080;">0</span> ; i < n ; i++<span style="color: #000000;">)
</span><span style="color: #008080;">59</span> <span style="color: #0000ff;">for</span> ( <span style="color: #0000ff;">int</span> j = <span style="color: #800080;">0</span> ; j < n ; j++<span style="color: #000000;">)
</span><span style="color: #008080;">60</span> <span style="color: #000000;"> {
</span><span style="color: #008080;">61</span> <span style="color: #0000ff;">if</span> (i==<span style="color: #000000;">j)
</span><span style="color: #008080;">62</span> <span style="color: #000000;"> {
</span><span style="color: #008080;">63</span> d[i][j]=<span style="color: #800080;">0</span><span style="color: #000000;">;
</span><span style="color: #008080;">64</span> <span style="color: #000000;"> }
</span><span style="color: #008080;">65</span> <span style="color: #0000ff;">else</span>
<span style="color: #008080;">66</span> <span style="color: #000000;"> {
</span><span style="color: #008080;">67</span> d[i][j] =<span style="color: #000000;">dis(i,j);
</span><span style="color: #008080;">68</span> <span style="color: #000000;"> }
</span><span style="color: #008080;">69</span> <span style="color: #000000;"> }
</span><span style="color: #008080;">70</span>
<span style="color: #008080;">71</span> <span style="color: #0000ff;">for</span> ( <span style="color: #0000ff;">int</span> k = <span style="color: #800080;">0</span> ; k < n ; k++<span style="color: #000000;">)
</span><span style="color: #008080;">72</span> <span style="color: #0000ff;">for</span> ( <span style="color: #0000ff;">int</span> i = <span style="color: #800080;">0</span> ; i < n ; i++<span style="color: #000000;">)
</span><span style="color: #008080;">73</span> <span style="color: #0000ff;">for</span> ( <span style="color: #0000ff;">int</span> j = <span style="color: #800080;">0</span> ; j < n; j++<span style="color: #000000;"> )
</span><span style="color: #008080;">74</span> d[i][j] =<span style="color: #000000;"> min(d[i][j],max(d[i][k],d[k][j]));
</span><span style="color: #008080;">75</span>
<span style="color: #008080;">76</span> <span style="color: #008000;">//</span><span style="color: #008000;"> printf("%fn",d[0][1]);</span>
<span style="color: #008080;">77</span> printf(<span style="color: #800000;">"</span><span style="color: #800000;">Frog Distance = %.3fn</span><span style="color: #800000;">"</span>,d[<span style="color: #800080;">0</span>][<span style="color: #800080;">1</span><span style="color: #000000;">]);
</span><span style="color: #008080;">78</span> puts(<span style="color: #800000;">""</span><span style="color: #000000;">);
</span><span style="color: #008080;">79</span> <span style="color: #000000;"> }
</span><span style="color: #008080;">80</span>
<span style="color: #008080;">81</span>
<span style="color: #008080;">82</span> <span style="color: #000000;"> #ifndef ONLINE_JUDGE
</span><span style="color: #008080;">83</span> <span style="color: #000000;"> fclose(stdin);
</span><span style="color: #008080;">84</span> <span style="color: #0000ff;">#endif</span>
<span style="color: #008080;">85</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">0</span><span style="color: #000000;">;
</span><span style="color: #008080;">86</span> }
View Code