先上题目:

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. Java Swing Action 动作

    Swing包提供了一种非常实用的机制来封装命令,并将它们连接到多个事件源,这就是Action接口.一个动作是一个封装下列内容的对象: × 命令的说明(一个文本字符串和一个可选图标): × 执行命令所需 ...

  2. 基于spark和flink的电商数据分析项目

    目录 业务需求 业务数据源 用户访问Session分析 Session聚合统计 Session分层抽样 Top10热门品类 Top10活跃Session 页面单跳转化率分析 各区域热门商品统计分析 广 ...

  3. C. Unusual Product(cf)

    http://codeforces.com/problemset/problem/405/C 题意: 给出一个n*n的矩阵,有q个操作,输入3时,输出A ,A等于第i行乘以第i列的对应元素的和(mod ...

  4. 确定比赛名次(toposort)

    http://acm.hdu.edu.cn/showproblem.php?pid=1285 #include <stdio.h> #include <string.h> ; ...

  5. [Apple开发者帐户帮助]九、参考(5)支持的功能(tvOS)

    tvOS应用程序可用的功能取决于您的程序成员身份. 能力 ADP 企业 Apple开发者 应用程序组 相关域名   背景模式 数据保护 游戏中心     游戏控制器 HomeKit iCloud:Cl ...

  6. Django day27 认证组件,权限组件()

    一:认证组件 1.写一个类 class LoginAuth(): # 函数名一定要叫authenticate,接收必须两个参数,第二个参数是request对象 def authenticate(sel ...

  7. 题解报告:hdu 1564 Play a game(找规律博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1564 Problem Description New Year is Coming! ailyanlu ...

  8. Servlet访问路径的两种方式、Servlet生命周期特点、计算服务启动后的访问次数、Get请求、Post请求

    Servlet访问路径的两种方式: 1:注解 即在Servlet里写一个@WebServlet @WebServlet("/myServlet") 2:配置web.xml < ...

  9. Python随笔-字符串

    函数title.lower.upper. ct = "hello WORLD" print(ct.title()) #title 以首字母大写的方式显示每个单词 print(ct. ...

  10. HashMap , TreeMap , TreeMap 默认排序

    Java代码  import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java. ...