HDU1245 Saving James Bond (shortest circuit + simple geometry)

Source: Internet
Author: User

Saving James BondTime limit:6000/3000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 2405 Accepted Submission (s): 454


Problem DescriptionThis time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world ' s most famous spy, is captured by a group of drug dealers. He is sent to a small piece by the 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 the last crocodile could bite him (actually the stunt man is caught by the big mouth a nd barely escaped with his extra thick boot).
Assume the lake is a 100x100 square one.Assume that the center of the lake was at (0,0) and the northeast corner at (50,50). The central island was a disk centered at (0,0) with the diameter of 15. A number of crocodiles is in the lake at various positions. Given the coordinates of each crocodile and the distance so James could jump, your must tell him whether he could escape. If He could,tell him the shortest length he had to jump and the min-steps he had to jump for shortest length.

Inputthe 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 for each crocodile, containing the (x, y) location of the crocodile. Note that x and y is both integers, and no crocodiles is staying at the same position.

Outputfor Each test case, if James can escape, output on one line the shortest length he have to jump and the min-steps he Have to jump for shortest length. If It is impossible for James to escape the that, simply ouput "can ' t be saved".

Sample Input
4 1017 027 037 045 01 1020 30

Sample Output
42.50 5can ' is saved test instructions: There is a 100*100 square pool stools, the center of the coordinate (0,0) representation of the two-dimensional coordinates, the center has a piece of land (0,0) as the center of the circle, the diameter of 15, the pool stools have n alligator, coordinate position given. Now there is a person in the pool center of the land, to flee to shore up, can step on the crocodile past, the farthest can only jump D meters, ask the shortest way and at least a few jumps. If the land cannot be reached, the outputcan ' t be savedAnalysis: N carp as a point, a person's starting point, and another is the destination (land) is a point. A total of n+2 points;  
#include <stdio.h> #include <math.h> #include <queue>using namespace std;const int N = 105;const double inf = 0x3ffffffff;int N,step[n],x[n],y[n];d ouble dis[n],mapt[n][n],d;int ABS (int a) {return a<0?-a:a;}        void Init () {for (int i=1;i<n;i++) {mapt[0][i]=mapt[i][0]=sqrt (x[i]*x[i]+y[i]*y[i]*1.0)-7.5;        if (mapt[0][i]>d) Mapt[0][i]=mapt[i][0]=inf;        Double Tx=abs (X[i]), Ty=abs (Y[i]);        if (tx<ty) tx=ty;        if (50.0-tx<=d) mapt[n][i]=mapt[i][n]=50.0-tx;    else Mapt[n][i]=mapt[i][n]=inf;    } if (d>=50-7.5) mapt[0][n]=mapt[n][0]=50-7.5;    else Mapt[0][n]=mapt[n][0]=inf; for (int i=1;i<n;i++) for (int j=1;j<n;j++) {mapt[i][j]=sqrt ((X[i]-x[j]) * (X[i]-x[j]) + (Y[i]-y[j]) * (y[i]-y        [j]));    if (mapt[i][j]>d) Mapt[i][j]=inf; } for (int i=0;i<=n;i++) dis[i]=inf,step[i]=99999999;}    void Spfa () {int inq[n]={0},s;    queue<int>q; Dis[0]=0;    step[0]=0;    Q.push (0);        while (!q.empty ()) {S=q.front (); Q.pop ();        inq[s]=0;                for (int i=1;i<=n;i++) if (mapt[s][i]!=inf) {if (Dis[i]>dis[s]+mapt[s][i]) {                step[i]=step[s]+1;                Dis[i]=dis[s]+mapt[s][i];            if (inq[i]==0) Q.push (i), inq[i]=1; } else if (dis[i]==dis[s]+mapt[s][i]&&step[i]>step[s]+1) {step[i]=step[s]+                1;            if (inq[i]==0) Q.push (i), inq[i]=1;        }}}}int Main () {while (scanf ("%d%lf", &n,&d) >0) {x[0]=y[0]=0; n++;        for (int i=1;i<n;i++) scanf ("%d%d", &x[i],&y[i]);        Init ();        SPFA ();        if (dis[n]==inf) printf ("Can ' t be saved\n");    else printf ("%.2lf%d\n", Dis[n],step[n]); }}



HDU1245 Saving James Bond (shortest circuit + simple geometry)

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.