POJ培训计划2253_Frogger(最短/floyd)

POJ培训计划2253_Frogger(最短/floyd)

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

解决报告

意甲冠军:

乞讨0至1所有最大的道路值的最小数量。

思维:

floyd。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define inf 0x3f3f3f3f
using namespace std;
int n,m,q;
double mmap[210][210];
struct node {
    double x,y;
} p[210];
double dis(node p1,node p2) {
    return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
void floyd() {
    for(int k=0; k<n; k++)
        for(int i=0; i<n; i++)
            for(int j=0; j<n; j++)
                mmap[i][j]=min(mmap[i][j],max(mmap[i][k],mmap[k][j]));
}
int main() {
    int i,j,u,v,w,k=1;
    while(~scanf("%d",&n)) {
        if(!n)break;
        for(i=0; i<n; i++) {
            for(j=0; j<n; j++)
                mmap[i][j]=(double)inf;
            mmap[i][i]=0;
        }
        for(i=0; i<n; i++) {
            scanf("%lf%lf",&p[i].x,&p[i].y);
        }
        for(i=0; i<n; i++) {
            for(j=0; j<n; j++) {
                mmap[i][j]=dis(p[i],p[j]);
            }
        }
        floyd();
        printf("Scenario #%d\n",k++);
        printf("Frog Distance = %.3lf\n",mmap[0][1]);
        printf("\n");
    }
    return 0;
}

Frogger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 25958   Accepted: 8431

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116705.html原文链接:https://javaforall.net

(0)
上一篇 2022年1月17日 上午9:00
下一篇 2022年1月17日 上午10:00


相关推荐

  • 使用Vue写一个登录页面

    使用Vue写一个登录页面上一博客讲到构建了一个vue项目,现在在那个项目之上实现一个登录页面。1.构建项目的目录2.App.vue&lt;template&gt;&lt;divid="app"&gt;&lt;router-view/&gt;&lt;/div&gt;&lt;/template&gt;&lt;script&gt;exportdefault{

    2022年5月21日
    120
  • 约束最优化方法之最优性条件

    约束最优化方法之最优性条件一般性约束最优性条件前面几篇博客主要讲了无约束最优化问题的一些求解方法 从这一篇博客开始将开始讲有约束的最优化方法 首

    2026年3月18日
    1
  • amos路径分析结果怎么看_路径分析图怎么解读

    amos路径分析结果怎么看_路径分析图怎么解读基础准备草堂君在前面几篇文章中,介绍了AMOS软件的操作、分析原理、结构方程模型和各种拟合指标含义等内容,大家可以点击下面的文章链接回顾,也可以从公众号导航栏获取AMOS分析技术(导航页)回顾:AMOS分析技术:软件安装及菜单功能介绍;这次是视频教程AMOS分析技术:结构方程模型的拟合度评价指标AMOS分析技术:模型整体拟合度指标AMOS分析

    2022年8月24日
    13
  • harbor搭建详解(仓库阁楼搭建效果图)

    一、Harbor介绍Docker容器应用的开发和运行离不开可靠的镜像管理,虽然Docker官方也提供了公共的镜像仓库,但是从安全和效率等方面考虑,部署私有环境内的Registry也是非常必要的。Harbor是由VMware公司开源的企业级的DockerRegistry管理项目,它包括权限管理(RBAC)、LDAP、日志审核、管理界面、自我注册、镜像复制和中文支持等功能二、环境准备Harbo…

    2022年4月18日
    51
  • tomcat的安装与配置[通俗易懂]

    tomcat的安装与配置[通俗易懂]tomcat的安装与配置

    2022年4月25日
    49
  • 【实例分割】1、SOLOv1: Segmenting Objects by Locations_2019[通俗易懂]

    【实例分割】1、SOLOv1: Segmenting Objects by Locations_2019[通俗易懂]文章目录一、背景二、本文方法三、本文方法的具体做法3.1问题定义3.1.1Semanticcategory3.1.2InstanceMask3.2NetworkArchitecture3.3SOLOlearning3.3.1LabelAssignment3.3.2LossFunction3.4Inference四、实验4.1主要结果4.2HowSOLOwork……

    2022年8月23日
    7

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号