POJ 2472 106 miles to Chicago

Axure RP 10表单数据提交制作 本文介绍了如何使用Axure RP 10实现表单数据提交。 阅读详情

Description

In the movie "Blues Brothers", the orphanage where Elwood and Jack were raised may be sold to the Board of Education if they do not pay 5000 dollars in taxes at the Cook Country Assessor's Office in Chicago. After playing a gig in the Palace Hotel ballroom to earn these 5000 dollars, they have to find a way to Chicago. However, this is not so easy as it sounds, since they are chased by the Police, a country band and a group of Nazis. Moreover, it is 106 miles to Chicago, it is dark and they are wearing sunglasses. 
As they are on a mission from God, you should help them find the safest way to Chicago. In this problem, the safest way is considered to be the route which maximises the probability that they are not caught.

Input

The input contains several test cases. 
Each test case starts with two integers n and m (2 <= n <= 100 , 1 <= m <= n*(n-1)/2). n is the number of intersections, m is the number of streets to be considered. 
The next m lines contain the description of the streets. Each street is described by a line containing 3 integers a, b and p (1 <= a, b <= n , a != b, 1 <= p <= 100): a and b are the two end points of the street and p is the probability in percent that the Blues Brothers will manage to use this street without being caught. Each street can be used in both directions. You may assume that there is at most one street between two end points. 
The last test case is followed by a zero.

Output

For each test case, calculate the probability of the safest path from intersection 1 (the Palace Hotel) to intersection n (the Honorable Richard J. Daley Plaza in Chicago). You can assume that there is at least one path between intersection 1 and n. 
Print the probability as a percentage with exactly 6 digits after the decimal point. The percentage value is considered correct if it differs by at most 10-6 from the judge output. Adhere to the format shown below and print one line for each test case.

Sample Input

5 7
5 2 100
3 5 80
2 3 70
2 1 50
3 4 90
4 1 85
3 1 70
0

Sample Output

61.200000 percent

Source







哎~ 最短路看成了最小生成树,wa了5发,最后还是队友做出了的,

这里我贴出来队友的floyd  我后来写的dijkstra,还有比赛的错误的最小生成树(引以为戒)


队友的:


#include<cstdio>
#include<cstring>
const int maxn=100+10;
#define INF 10000000
double dis[maxn][maxn];
int n,m;

void floyd()
{
   for(int k=1;k<=n;k++)
       for(int i=1;i<=n;i++)
           for(int j=1;j<=n;j++)
              {
                  if(dis[i][j]<dis[i][k]*dis[k][j])
                       dis[i][j]=dis[i][k]*dis[k][j];
              }
}


int main()
{
    int u,v,w;
    while(~scanf("%d",&n),n)
    {
         scanf("%d",&m);
         for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
         {
             if(i==j)  dis[i][j]=0;
             else
                dis[i][j]=dis[j][i]=-1;
         }
         for(int i=1;i<=m;i++)
         {
             scanf("%d%d%d",&u,&v,&w);
             dis[u][v]=dis[v][u]=(w*1.0)/100;
         }
         floyd();
         printf("%.6f percent\n",dis[1][n]*100);
    }
    return 0;
}



dijkstra:


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 105

double a[N][N];
double dis[N];
int vis[N];
int n,m;

void dijkstra()
{
    int i,j,now;

    memset(dis,0,sizeof(dis));
    memset(vis,0,sizeof(vis));

    dis[1]=1;

    for(i=1;i<=n;i++)
    {
        now=1;
        double temp=0;

        for(j=1;j<=n;j++)
          if(!vis[j]&&dis[j]>temp)
          {
              temp=dis[j];
              now=j;
          }



          vis[now]=1;
          for(j=1;j<=n;j++)
            if(!vis[j]&&a[now][j]>0)
          {
                dis[j]=max(dis[j],dis[now]*a[now][j]);
          }
    }

    printf("%.6f percent\n",dis[n]*100);
}
int main()
{
    int i,j;
    while(~scanf("%d",&n),n)
    {
        scanf("%d",&m);
        memset(a,0,sizeof(a));

        int x,y;
        double len;

        while(m--)
        {
            scanf("%d%d%lf",&x,&y,&len);
            a[x][y]=a[y][x]=len*1.0/100;
        }

        dijkstra();
    }
    return 0;
}



错误的最小生成树(至今没有想通,求大神 告诉小弟原因)



#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define N 100005

struct stud{
int a,b;
double s;
}f[N];

int n,m;
int father[1005];


int cmp(stud a,stud b)
{
    return a.s<b.s;
}

int cha(int x)
{
    if(x!=father[x])
        father[x]=cha(father[x]);
    return father[x];
}

void inset()
{
    int i;
    for(i=0;i<1000;i++)
        father[i]=i;
}

void fdd()
{
    int i,j;
    double ans=0;

    for(i=0;i<m;i++)
    {
        inset();
        double x=1;

        for(j=i;j<m;j++)
        {
            int aa=cha(f[j].a);
            int bb=cha(f[j].b);

            if(aa!=bb)
            {
                father[aa]=bb;
                x=f[j].s*x/100;

                if(cha(1)==cha(n))
                {
                    if(ans<x)
                        ans=x;
                    break;
                }
            }
        }
    }

    ans=ans*100;

    printf("%.6f percent\n",ans);
}

int main()
{
    int i;
    while(scanf("%d",&n),n)
    {
        scanf("%d",&m);

        for(i=0;i<m;i++)
            {
            scanf("%d%d%lf",&f[i].a,&f[i].b,&f[i].s);
            }

        sort(f,f+m,cmp);

        fdd();
    }
    return 0;
}




【AIGC】Qwen3-Embedding:Embedding与Rerank模型新标杆 Qwen3-Embedding:文本嵌入与重排序模型的技术解析与应用实践 阅读详情

相关推荐

1173:阶乘和

1173:阶乘和 时间限制: 1000 ms 内存限制: 65536 KB 提交数: 6010 通过数: 3049 【题目描述】 用高精度计算出S=1!+2!+3!+…+n!(n≤50),其中“!”表示阶乘,例如:5!=5×4×3×2×1。 输入正整数n,输出计算结果S。 【输入】 一个正整数n。 【输出】 计算结果S。 【输入样例】 5 【输出样例】 153 思路: ...

zqhf123的博客 1261

POJ -2472(乘积最短路)

题目链接: 106 miles to Chicago 题意 现在一个逃犯想要逃脱警察的追捕,他有很多路可以走,告诉你了他走这条路不被抓住的概率,现在让你求他从1点走出N点不被抓住的最大概率。 思路 首先概率应该是乘积,所以初始化就会有一些变动,权值代表的是概率,权值为0就代表一定会被抓住,所以一开始的初始化就是都赋值为0,dist[1] = 1,代表到自身一定不会被抓住。然后就是dijkstra了...

“”云腾致雨“”的博客 751

蓝桥杯FPGA赛道积分赛

代码如下: 按键驱动 代码如下 按键驱动 代码如下: 顶层文件 按键驱动 数码管驱动 声明:本代码借鉴网络资料,如有侵权和错误请联系作者删除。我是从寒假开始备赛的,由于我基础不行,备赛过程中也是混混呃呃的,备赛效率不高,总体来说备赛不认真,有点拖拉,但是最后我也坚持备赛到了今天,在备赛过程中,即复习了旧的东西,也学到了新的东西,总结起来还是有点收获的,后天北京、天津、河北地区就要进行省赛了,我会全力以赴,不管结果怎么样,尽力就好,最后祝大家都能

weixin_69804913的博客 1991

POJ2472:最长路

POJ2472 题意:求从1到n不被逮捕的概率最大 题解: Dijkstra算法不能直接求最长路。按照Dijkstra求下面的从1到2的最长路,会发生错误。必须取反再求。1—2 2,1—3 1,3—4 1,4—2 1。(空格后面是边权) 但是这一题可以用Dijkstra求最大值(47ms)。因为概率≤1,所以越乘越小。比如现在到b点的概率p1为最大,就做标记。那么从其它点跑到b...

FlyingJack 1284

3D Gaussian Splatting环境配置和运行

使用conda命令根据environment.yml文件创建虚拟环境时,安装的pytorch是使用conda install 命令来安装的,实际上并不能成功安装带有gpu的pytorch,而这两个模块的安装依赖于带gpu的pytorch。如果不注释掉这三行,直接安装会报错

m0_46360757的博客 3326

别再只盯着时序了!聊聊SDC里那些容易被忽略的‘配角’命令:工作条件、线载模型与面积约束

本文深入探讨了SDC(设计约束)中常被忽视的关键命令,包括set_operating_conditions、set_wire_load_model和set_max_area。这些‘配角’命令在芯片设计中扮演着至关重要的角色,影响时序收敛、功耗和面积优化。文章通过实际案例和最佳实践,揭示了如何正确配置工作条件、选择线载模型以及动态调整面积约束,以提升设计质量和效率。

weixin_26875109的博客 208

poj2472解题报告——化用Dijkstra算法

此题是求特定两点之间路径乘积的最大值,可以将原路径值取以小于1的数为底的对数值,然后套用Dijkstra算法即可。         Dijkstra算法与Prim算法很接近,但要明确Dijkstra算法求的是某个特定顶点到其他所有顶点的最短路径,此特定顶点属于特殊点,须最先纳入已找到顶点的集合中;而Prim算法则只是求最小生成树,顶点之间无区别,故第一个纳入已找到顶点集合的可以是任意点。因此,在

江湖中人的专栏 742

华为OD机试 - 机器人活动区域(Python/JS/C/C++ 双机位C卷 200分)

本专栏收录于《华为OD机试真题(Python/JS/C/C++)》。刷的越多,抽中的概率越大,私信哪吒,备注华为OD,加入华为OD刷题交流群,每一题都有详细的答题思路、详细的代码注释、3个测试用例、为什么这道题采用XX算法、XX算法的适用场景,发现新题目,随时更新。现有一个机器人,可放置于 M × N的网格中任意位置,每个网格包含一个非负整数编号。当相邻网格的数字编号差值的绝对值小于等于 1 时,机器人可在网格间移动问题:求机器人可活动的最大范围对应的网格点数目。说明:1)网格左上角坐标为 (0, 0),右

学Java,找哪吒 1434

Poj 2472 106 miles to Chicago【Floyd】

106 miles to Chicago Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4692   Accepted: 2120   Special Judge Description In the movie "Blues Brothers", the

mengxiang000000 772

上位机图像处理和嵌入式模块部署(开篇)

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】 图像处理是现实生活当中很实用的一门技术。工业上一般采用的是机器视觉,以传统算法和光源控制为主,部分采用了深度学习技术。而生活当中,则主要以二维码识别、人脸识别、车牌识别和ocr识别为主,这中间深度学习与AI扮演了很重要的角色。过去,市场上的商业收费软件,主要还是以传统设备厂商提供的上位机软件为主,那这一部分是不是结合最新的npu技术,应该做出一些新的东西出来呢?

嵌入式-老费,一个分享专业嵌入式知识的blog 1337

复旦微实现串口在线升级BOOT.BIN

将该 demo 生成的 app(升级用)和 fsbl、最简化 bit 文件(可选)打包成 BOOT.BIN,作为 golden image 烧写在 qspi flash 偏移 0 地址开始的位置,其中最简化 bit 文件为在线升级功能提供必要的物理通道(如果不需要,可以不打包该文件),golden image 一旦发布基本不需要进行升级,由该 golden image 负责和上位机进行通信交互,完成业务 app、业务 bit 文件、uboot 以及操作系统 image 等文件在线升级,在qspi flash

wangjie36的博客 3174

POJ 2472 迪杰斯特拉计算最长路

需要注意的就是自己到自己是百分之百 其实用Floyd算法更加简便。因为时间限制是2秒。 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;algorithm&gt; #include&lt;cstring&gt; #include&lt;string&gt; #include&lt;map&gt; #include&lt;v...

兜率工的博客 2384

innovus:set_clock_latency与insertion_delay

当1ns clock latency设置在capture上,在report_timing报告中体现在other end arrival time以及capture clock path的Arrival Time上。因为-1ns的insertion delay存在,所以skew group报告中显示的Arrival (ns)是减1ns的结果,即1.819-1=0.819 ns。CTS阶段create_ccopt_clock_tree_spec之后,spec中会产生对应的insertion_delay命令。

m0_61544122的博客 1621

poj 2472 106 miles to Chicago

因为求安全性最大的路径,所以可以将dist[1]定为-1,再作spfa处理 //poj 2472 106 miles to Chicago /* * 因为求安全性最大的路径,所以可以将dist[1]定为-1,再作spfa处理 * spfa(st) 之后有dist[]得到距离 */ //licatweijei #include using namespace std; #def

LiWeiJie的专栏 657

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

poj 2472 106 miles to Chicago floyd

View Code #include <stdio.h>#include <string.h>int n,m;double map[105][105];void floyd(){ int i,j,k; for (i=1;i<=n;i++) { for (j=1;j<=n;j++) { ...

diaopi1575的博客 190

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

POJ 2472 106 miles to Chicago

106 miles to Chicago Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3305   Accepted: 1557   Special Judge Description In the movie "Blues Brothers", the orp...

weixin_34149796的博客 87

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

POJ-2472 106 miles to Chicago

106 miles to Chicago Time Limit: 2000MS   Memory Limit: 65M         Special Judge Description In the movie "Blues Brothers", the orphanage where Elwood and Jack were ra

JSure的代码库 1090

POJ 2472 106 miles to Chicago(最短路)

题目连接:http://poj.org/problem?id=2472 题意:男孩要从1到n城市,每条道路有他不被抓的百分比,输出他到n不被抓的最大概率。 题目的数据有些问题,边开到20W才过,求最长路径即可。 参考代码: #include #include #include #include using namespace std; #define INS 0.0 #define

fire__ice的专栏 736

POJ2472 106 miles to Chicago SPFA

一道最长路径,我分别试了两种方法,spfa 和 floyd 106 miles to Chicago Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2977   Accepted: 1401   Special Judge Description In the

834

【POJ】2472 106 miles to Chicago 最短路

传送门:【POJ】2472 106 miles to Chicago 题目分析:

poursoul 804

POJ 2472:106 miles to Chicago

Description Description In the movie "Blues Brothers", the orphanage where Elwood and Jack were raised may be sold to the Board of Education if they do not pay 5000 dollars in taxes at the Cook Coun

jjs98 673

POJ2472 106 miles to Chicago

简单最长路径,一个小技巧就是将每条边权值取对数,然后SPFA一次就可以了 #include #include #include using namespace std; const int MAXN = 110; const int MAXM = MAXN*MA

云游code的博客 1023

POJ 2472 106 miles to Chicago

题目链接题意:给定一张图,每条路有一定权值,代表不会被抓到的概率。求概率最大值。分析:对概率取对数后再去负号,相当于求最短路。裸的dijkstra.#include<stdio.h> #include <iomanip> #include<iostream> #include<cmath> using namespace std; const int MAX_N = 100; const doubl

HYB733093411的博客 397
上一篇: POJ 1840 数学
下一篇: POJ 3187 Backward Digit Sums(dfs)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值