Hdu 1245 Saving James Bond

Source: Internet
Author: User
Tags abs continue min pow time limit

Link:

http://acm.hdu.edu.cn/showproblem.php?pid=1245

Topic:

Saving James Bond
Time limit:6000/3000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 1066 accepted Submission (s): 186

Problem Description
This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world ' s most famous, Was captured by a group of drug dealers. He is sent to a small piece in the center of a lake filled with crocodiles. There He performed the most daring action to escape – he jumped onto the head of the nearest crocodile! Before the animal realized what is happening, James jumped again onto the next big head ... Finally he reached the bank before of the last crocodile could bite him (actually that man is stunt by the big caught a nd barely escaped with his extra thick boot).
Assume is a 100x100 square one. Assume, the center of the Lake are at (0,0) and the northeast corner at (50,50). The "island is" a disk centered at (0,0) with the diameter of 15. A number of crocodiles are in various positions. Given the coordinates of each crocodile and the distance that James could jump, you are must tell him whether he could escape. If He could,tell him the shortest length he has to jump and the min-steps him has to jump for shortest.

Input
The input consists of several test cases. Each case starts with a line containing n <=, the number of crocodiles, and D > 0, the distance that James could Jump. Then one line follows to each crocodile, containing the (x, y) location of the crocodile. Note that x and y are both integers, and no two crocodiles are to staying at the same.

Output
For each test case, if James can escape, output in one line the shortest length he has to jump and the min-steps him has to Jump for shortest length. If it is impossible as James to escape this way, simply ouput "can ' t be saved".

Sample Input

4 10
17 0
27 0
37 0
45 0
1 10

20 30

Sample Output

42.50 5

Can ' t be saved

Author
Weigang Lee

Recommend
Ignatius.l

Analysis and Summary:

The diagram is the key:

1. The whole of the island as a point 0, because the middle of the island diameter of 15, then each crocodile can jump from the island needs to be a special sentence, if a crocodile if the distance from the center point (0,0) for dis, so long as dis-7.5<=d, you can establish this edge of the relationship

2. See the whole shore as a point n+1, because each crocodile distance from the shore is also different, so also need to special sentence. The shortest distance of four banks per crocodile is weighted. Find the way to the shore: We know the range of the lake is (I,J), -50<i=j<50, for the crocodile coordinates (x,y), 50-max (ABS (x), ABS (Y)) is the shortest distance from the shore of this coordinate.

3. Trick Difficult to find:

(1) For each crocodile's coordinates, may be illegal, may be in the middle of the island, can also be on the shore, so need to filter the first judgment.

(2) If James Bond can jump a distance of D greater than 42.50 (the distance from the island to the shore), then you can jump directly ashore, the step number is 1

After the diagram is built, the shortest path algorithm can be used to calculate.

In addition, because the number of steps to calculate, and then add a weight step, all assigned to 1 can

Code:

With Dijkstra

#include <cstdio> #include <cstring> #include <math.h> #include <iostream> using namespace St  
    
D  
typedef double TYPE;  
const int VN = 205;  
    
const int INF=0X7FFFFFFF/2;  
int n,size;  
Double D;  
Double X[VN];  
Double Y[VN];  
Type D[VN];  
Type W[VN][VN];  
int S[VN][VN];  
int STEP[VN];  
BOOL VIS[VN];  
int POS;  
    
int END[VN];  
Double getdist (int i, int j) {return sqrt (POW (x[i]-x[j],2) +pow (y[i]-y[j],2));   
    } void Init () {pos = 0;  
    size=0;  
X[0] = y[0] = 0;         
Double Bankdist (Double I, double j) {//Increase the point return on the Shore 50*1.0-max (Fabs (i), Fabs (j));  
    } void Dijkstra (int src) {memset (Vis, 0, sizeof (VIS));  
    for (int i=0; i<=n; ++i) D[i]=inf,step[i]=inf;  
    STEP[SRC] = d[src] = 0;  
        for (int i=0; i<=n; ++i) {int u=-1;  
        for (int j=0; j<=n; ++j) if (!vis[j]) {if (U==-1 | | d[j]<d[u)) u=j;  
        } Vis[u] = 1; for (int j=0; j<=n;  
            ++J) if (!vis[j]) {Type tmp = d[u]+w[u][j];  
            int tmp_s = Step[u]+s[u][j];   
                if (d[j]>tmp) {d[j]=tmp;  
            step[j]=tmp_s;  
        else if (d[j]==tmp&&step[j]>tmp_s) step[j]=tmp_s;  
    int main () {double a,b;  
            while (~SCANF ("%d%lf", &n,&d)) {if (d>=42.5) {puts ("42.50 1");  
        Continue  
        Init ();  
            for (int i=1; i<=n; ++i) {scanf ("%lf%lf", &a,&b);  
            if (Fabs (a) <=7.5&&fabs (b) <=7.5 | | fabs (a) >50 | | fabs (b) >50) continue;  
        X[++size]=a, y[size]=b;  
        } n = size+1;  
            for (int i=0; i<=n; ++i) {w[i][i] = INF;  
            S[i][i] = 0;  
                for (int j=i+1; j<=n; ++j) {w[i][j]=w[j][i]=inf; s[i][J]=s[j][i]=1;  
            for (int i=1; i<=size; ++i) {Double dis = getdist (0,i);  
            if (Dis-7.5<=d) {//small island can hop on point, the whole island is dot 0 w[0][i] = w[i][0] = dis-7.5;  
            //Can jump from this point to shore dis = bankdist (x[i],y[i]);  
            if (Dis<=d) {W[i][n]=w[n][i]=dis;  
                for (int j=i+1; j<=size; ++j) {dis = getdist (i,j);  
                if (Dis<=d) {w[i][j] = w[j][i] = dis;  
        }} Dijkstra (0);  
        if (d[n]!=inf) printf ("%.2f%d\n", D[n],step[n]);  
    Else puts ("can ' t be saved");  
return 0; }

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.