先上题目:

Chasing Girl

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)
SubmitStatus

Problem Description

YYS 是SCAU_ACM里相当有名气的高富帅, 又因为他曾代表SCAU参加 World Final 而被各路亲朋好友仰慕。但YYS 又有另外一个嗜好,就是泡妞。在大学的时候,他经常去找各个女友玩耍, 但在路上却又整天遇到膜拜他的渣渣,这令他非常烦恼。于是, 他每次去找女友都希望尽量避开膜拜他的渣渣。
       YYS 把校园抽象成n个点, m条双向路组成的图。由多次经验他统计出在某条路上遇到渣渣的概率, 他现在要从A走到B, 由于他急于跟女友xxx, 所以想选择一条长度最短,在此基础上遇到渣渣概率最小的路径。YYS此时的心思只有女友, 他想你帮他算一下, 最短的路径长度和最小的概率是多少。

Input

第一行一个整数T,代表测试数据的组数。
对每组数据, 
第一行, 两个整数n, m
接下来m行,每行4个整数 u, v, w, p, 代表u,v之间有一条长度为w双向路,在这条路遇到渣渣的概率为p%
最后一行, 两个整数A, B

数据范围:
1 <= T <= 100
1 <= n <= 1000
1 <= m <= 10000
1 <= u, v, A, B <= n
1 <= w <= 100
0 <= p < 100

数据保证无重边、无自环,并且A、B之间至少有一条路径。

Output

对每组数据,输出最短的路径长度和最小的概率(保留6位小数)。

Sample Input

2
4 4
1 2 1 50
2 3 2 50
1 4 5 20
4 3 3 30
2 4 4 4
1 2 1 50
2 3 2 50
1 4 4 20
4 3 3 30
2 4

Sample Output

5 0.650000
5 0.600000   比较简单的最短路,求一次最短路,同时算一下一路上不会遇到那些人的概率,如果遇到将要修改的距离等于已经得到的最短距离的话,就根据概率来判断,如果概率变大了就更新为新的概率。
  输出的时候概率用1减一次就得到结果了(1-反面的概率)。
  这里的图是有环的,看自己的笔记好像是说DIJ只可以求DAG,所用用了SPFA,但是小伙伴说用DIJ也过了······ 上代码:
 /*
* this code is made by sineatos
* Problem: 1180
* Verdict: Accepted
* Submission Date: 2014-07-31 15:23:49
* Time: 228MS
* Memory: 1884KB
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#define MAX 10002
#define INF (1<<30)
#define ll long long
using namespace std; int n,m,st,ed; typedef struct{
int to,next,l;
double p;
}edge; edge e[MAX<<];
int p[MAX],tot;
int dist[MAX];
double pa[MAX];
queue<int> q;
bool vis[MAX]; inline void add(int u,int v,int l,int per){
e[tot].to=v; e[tot].l=l; e[tot].p=-(per*1.0/); e[tot].next=p[u]; p[u]=tot++;
} void spfa(){
for(int i=;i<=n;i++) dist[i]=INF;
memset(vis,,sizeof(vis));
while(!q.empty()) q.pop();
dist[st]=;
pa[st]=;
vis[st]=;
q.push(st);
while(!q.empty()){
int u = q.front();
q.pop();
vis[u]=;
for(int i=p[u];i!=-;i=e[i].next){
if(e[i].l+dist[u]<dist[e[i].to]){
dist[e[i].to]=e[i].l+dist[u];
pa[e[i].to]=pa[u]*e[i].p;
if(!vis[e[i].to]){
vis[e[i].to]=;
q.push(e[i].to);
}
}else if(e[i].l+dist[u]==dist[e[i].to] && pa[e[i].to]<pa[u]*e[i].p){
pa[e[i].to]=pa[u]*e[i].p;
if(!vis[e[i].to]){
vis[e[i].to]=;
q.push(e[i].to);
}
}
}
}
} int main()
{
int t,u,v,l,per;
//freopen("data.txt","r",stdin);
scanf("%d",&t);
while(t--){
scanf("%d %d",&n,&m);
memset(p,-,sizeof(p));
tot=;
for(int i=;i<m;i++){
scanf("%d %d %d %d",&u,&v,&l,&per);
add(u,v,l,per);
add(v,u,l,per);
}
scanf("%d %d",&st,&ed);
spfa();
printf("%d %.6lf\n",dist[ed],-pa[ed]);
}
return ;
}

/*Chasing Girl*/

ACDream - Chasing Girl的更多相关文章

  1. ACdream 1214---矩阵连乘

    ACdream 1214---矩阵连乘 Problem Description You might have noticed that there is the new fashion among r ...

  2. acdream.LCM Challenge(数学推导)

     LCM Challenge Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit ...

  3. acdream.Triangles(数学推导)

    Triangles Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Stat ...

  4. acdream.A Very Easy Triangle Counting Game(数学推导)

    A - A Very Easy Triangle Counting Game Time Limit:1000MS     Memory Limit:64000KB     64bit IO Forma ...

  5. acdream.Bet(数学推导)

    Bet Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Status Pra ...

  6. acdream.郭式树(数学推导)

    郭式树 Time Limit:2000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit Status Pr ...

  7. ACdream 1188 Read Phone Number (字符串大模拟)

    Read Phone Number Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Sub ...

  8. ACdream 1195 Sudoku Checker (数独)

    Sudoku Checker Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit ...

  9. ACdream 1112 Alice and Bob(素筛+博弈SG函数)

    Alice and Bob Time Limit:3000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit ...

随机推荐

  1. JZOJ 1003 [ 东莞市选 2007 ] 拦截导弹 —— 递推

    题目:https://jzoj.net/senior/#main/show/1003 n^2 的话递推就可以啦. 代码如下: #include<iostream> #include< ...

  2. windows 多mysql 实例

  3. openStack aio nova service-list neutron ext-list

  4. oracle 分页方法

    我分享两种: 1.用rownum select * from (select p.* , rownum rn  from t_premium p where rn<= page * 10) a ...

  5. bzoj1036 树的统计(树链剖分+线段树)

    1036: [ZJOI2008]树的统计Count Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 15120  Solved: 6141[Submit ...

  6. null, undefined,"",0,false是什么关系?

    null本质上和0,"",false是一类东西,它们都表示一种数据类型的非值.正如0表示数字类型的非值,""表示字符类型的非值一样,null表示完全空的对象,即 ...

  7. [App Store Connect帮助]二、 添加、编辑和删除用户(5)创建一个沙盒测试员帐户

    如果您的 App 使用了 App 内购买项目或 Apple Pay,您可以在 App Store Connect 中创建沙盒测试员帐户,以便您向用户提供该 App 前,可以使用该帐户在测试环境中运行您 ...

  8. Django day26 初识认证组件

    一:什么是认证组件 只有认证通过的用户才能访问指定的url地址,比如:查询课程信息,需要登录之后才能查看,没有登录,就不能查看,这时候需要用到认证组件 二:认证组件源码分析

  9. scala的Class

    先看类的定义: package com.test.scala.test import scala.beans.BeanProperty /** * scala 的类 */ //定义一个scala的类 ...

  10. OFDM同步算法之Park算法

    park算法代码 训练序列结构 T=[\(C\) \(D\) \(C^{*}\) \(D^{*}\)],其中C表示由长度为N/4的复伪随机序列PN,ifft变换得到的符号序列 \(C(n) = D(N ...