题意:

     给你一个无向图,然后每条边的权值就是不被抓的概率,有个货要从1逃到n,问你他的最安全概率是多少?

思路:

      水题,直接跑就行了,一开始自己想多了,还转换了一下log,后来发现转换之后会有正环,有正环求最长路就呵呵了,直接跑就行了,具体看代码,我写的是spfa.


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<queue> #define N_node 100 + 10
#define N_edge 5500
#define INF 10000000 using namespace std; typedef struct
{
int to ,next;
double cost;
}STAR; STAR E[N_edge];
int list[N_node] ,tot;
double s_x[N_node]; void add(int a ,int b ,double c)
{
E[++tot].to = b;
E[tot].cost = c;
E[tot].next = list[a];
list[a] = tot;
} void Spfa(int s ,int n)
{
int mark[N_node] = {0};
for(int i = 0 ;i <= n ;i ++)
s_x[i] = -INF;
s_x[s] = 1 ,mark[s] = 1;
queue<int>q;
q.push(s);
while(!q.empty())
{
int tou ,xin;
tou = q.front();
q.pop();
mark[tou] = 0;
for(int k = list[tou] ;k ;k = E[k].next)
{
xin = E[k].to;
if(s_x[xin] < s_x[tou] * E[k].cost)
{
s_x[xin] = s_x[tou] * E[k].cost;
if(!mark[xin])
{
mark[xin] = 1;
q.push(xin);
}
}
}
}
return ;
} int main ()
{
int n ,m ,a ,b ,c ,i;
while(~scanf("%d" ,&n) && n)
{
scanf("%d" ,&m);
memset(list ,0 ,sizeof(list)) ,tot = 1;
for(i = 1 ;i <= m ;i ++)
{
scanf("%d %d %d" ,&a ,&b ,&c);
add(a ,b ,c * 0.01);
add(b ,a ,c * 0.01);
}
Spfa(1 ,n);
printf("%lf percent\n" ,s_x[n] * 100);
}
return 0;
}

poj 2472的更多相关文章

  1. POJ 2472 106 miles to Chicago(Dijstra变形——史上最坑的最长路问题)

    题目链接 :http://poj.org/problem?id=2472 Description In the movie "Blues Brothers", the orphan ...

  2. POJ 2472 106 miles to Chicago

    最短路问题变形. 题意是给你一些道路,和路过时不被抓的概率. 要求找一条到达目的地时不被抓的最大概率概率. 初始 dis[]设为 1 .其余为 0 .找最大就可以. #include<cstdi ...

  3. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  4. 图论常用算法之一 POJ图论题集【转载】

    POJ图论分类[转] 一个很不错的图论分类,非常感谢原版的作者!!!在这里分享给大家,爱好图论的ACMer不寂寞了... (很抱歉没有找到此题集整理的原创作者,感谢知情的朋友给个原创链接) POJ:h ...

  5. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  6. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  7. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  8. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  9. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

随机推荐

  1. 剑指 Offer 53 - II. 0~n-1中缺失的数字 + 二分法

    剑指 Offer 53 - II. 0-n-1中缺失的数字 Offer_53 题目详情 java代码 package com.walegarrett.offer; /** * @Author Wale ...

  2. mysql 使用sleep操作 update 来停止一段时间执行语句 [骚操作]

    update mytestTable inner join(select '2' as id, sleep(5)) a on mytestTable.id=a.id set mytestTable.n ...

  3. Mysql给外网IP授权访问

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'58.221.44.174' IDENTIFIED BY 'njqt123456' WITH GRANT OPTION; ...

  4. Git详解和Github的使用

    Git和Github的概念: Git是分布式版本管理系统,简单说就是一个软件,用于记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的软件. Github是一个为用户提供Git服务的网站,简单说 ...

  5. beego框架panic: 'GetSecurityInf' method doesn't exist in the controller CorporateInfcontroller问题解决

    在使用beego框架时,出现类似于panic: 'GetSecurityInf' method doesn't exist in the controller CorporateInfcontroll ...

  6. python文件处理之fileinput

    一.介绍 fileinput模块可以对一个或多个文件中的内容进行迭代.遍历等操作,我们常用的open函数是对一个文件进行读写操作. fileinput模块的input()函数比open函数更高效和好用 ...

  7. 回顾反射机制Method

    package com.demo.service; public interface SayHello { void sayHello(String name); } 接口实现类 package co ...

  8. elf.h

    1 /* This file defines standard ELF types, structures, and macros. 2 Copyright (C) 1995-2019 Free So ...

  9. 攻防世界 csaw2013reversing2 CSAW CTF 2014

    运行程序 flag显示乱码 IDA打开查看程序逻辑 1 int __cdecl __noreturn main(int argc, const char **argv, const char **en ...

  10. mybatis-plus的Could not set property 'updateDate' of 'class com.example.pojo.User' with value 'Fri Jul 24 10:29:39 CST 2020' Cause: java.lang.IllegalArgumentException: argument type mismatch解决方案

    按照官网在写mybatis-plus的自动填充功能一直报错,发现官网的解说不全,数据库是datetime类型,java程序又是date,类型不匹配 org.mybatis.spring.MyBatis ...