POJ 2253 Frogger

Source: Internet
Author: User

POJ 2253 Frogger

A frog finds another frog, but he can jump to the position of the target frog through other stones. when inputting data, the first group of data is the position of the first frog, the second group is the position of the target frog, and the other is the position of the stone.

Idea: the dijkstra algorithm has a small deformation, and the practice is the same.

Tips: the dual-precision floating point output on POJ turned out to be % f. I 've always been wrong, or the compilation is wrong, so it's annoying!

AC code:

#include
 
  #include
  
   #includeusing namespace std;#define maxn 100000000#define N 212struct p{    int x,y;};p  point[N];int n;double d[N];double dis(p a,p b){    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}void dijkstra(){    double minn;    int i,j,vis[N],v;    for(i=1;i<=n;i++)    {        vis[i]=0;        d[i]=maxn;    }    v=1;    d[1]=0;    for(i=1;i<=n;i++)    {        minn=maxn;        for(j=1;j<=n;j++)        {            if(!vis[j]&&d[j]
   
    max(d[v],dis(point[v],point[j])))d[j]=max(d[v],dis(point[v],point[j]));    }}int main(){    int cnt=1;    while(scanf("%d",&n)!=EOF)    {        if(n==0)break;        for(int i=1;i<=n;i++)            scanf("%d %d",&point[i].x,&point[i].y);        dijkstra();        printf("Scenario #%d\nFrog Distance = %.3f\n",cnt++,d[2]);        printf("\n");    }    return 0;}
   
  
 


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.