TYVJ P1933 绿豆蛙的归宿 题解(未完成)
背景
描述
到达每一个顶点时,如果有K条离开该点的道路,绿豆蛙可以选择任意一条道路离开该点,并且走向每条路的概率为 1/K 。
现在绿豆蛙想知道,从起点走到终点的所经过的路径总长度期望是多少?
输入格式
第二行到第 1+M 行: 每行3个整数 a b c,代表从a到b有一条长度为c的有向边
输出格式
测试样例1
输入
4 4
1 2 1
1 3 2
2 3 3
3 4 4
输出
7.00
备注
对于40%的数据 N<=1000
对于60%的数据 N<=10000
对于100%的数据 N<=100000,M<=2*N
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<iomanip>
#include<cassert>
#include<climits>
#define maxn 10001
#define F(i,j,k) for(int i=j;i<=k;i++)
#define M(a,b) memset(a,b,sizeof(a))
#define FF(i,j,k) for(int i=j;i>=k;i--)
#define inf 0x7fffffff
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct edge{
int to,w,next;
}p[];
int tot,n;
int head[];
void addedge(int a,int b,int c){
p[tot].to=b;
p[tot].w=c;
p[tot].next=head[a];
head[a]=tot++;
}
double dp[];
int out[],q[];
int out1[];
int main()
{
std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
int m,a,b,c;
cin>>n>>m;
M(head,-);
while(m--){
cin>>a>>b>>c;
addedge(b,a,c);
out[a]=++out1[a];
}
int s=,e=-;
q[++e]=n;
while(s<=e){
s++;
int u=q[s];
for(int i=head[u];i!=-;i=p[i].next){
int v=p[i].to;
dp[v]+=(dp[u]+p[i].w)/out[v];
if(--out1[v]==) q[++e]=v;
}
}
cout<<setiosflags(ios::fixed)<<setprecision()<<dp[];
cout<<endl;
return ;
}
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<iomanip>
#include<cassert>
#include<climits>
#define maxn 10001
#define F(i,j,k) for(int i=j;i<=k;i++)
#define M(a,b) memset(a,b,sizeof(a))
#define FF(i,j,k) for(int i=j;i>=k;i--)
#define inf 0x7fffffff
using namespace std;
int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
struct edge{
int to,w,next;
}p[200010];
int tot,n;
int head[100010];
void addedge(int a,int b,int c){
p[tot].to=b;
p[tot].w=c;
p[tot].next=head[a];
head[a]=tot++;
}
double dp[100010];
int out[100010],q[100010];
int out1[100010];
int main()
{
std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
int m,a,b,c;
cin>>n>>m;
M(head,-1);
while(m--){
cin>>a>>b>>c;
addedge(b,a,c);
out[a]=++out1[a];
}
int s=0,e=-1;
q[++e]=n;
while(s<=e){
s++;
int u=q[s];
for(int i=head[u];i!=-1;i=p[i].next){
int v=p[i].to;
dp[v]+=(dp[u]+p[i].w)/out[v];
if(--out1[v]==0) q[++e]=v;
}
}
cout<<setiosflags(ios::fixed)<<setprecision(2)<<dp[1];
cout<<endl;
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<iomanip>
#include<cassert>
#include<climits>
#define maxn 10001
#define F(i,j,k) for(int i=j;i<=k;i++)
#define M(a,b) memset(a,b,sizeof(a))
#define FF(i,j,k) for(int i=j;i>=k;i--)
#define inf 0x7fffffff
using namespace std;
int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
struct edge{
int to,w,next;
}p[200010];
int tot,n;
int head[100010];
void addedge(int a,int b,int c){
p[tot].to=b;
p[tot].w=c;
p[tot].next=head[a];
head[a]=tot++;
}
double dp[100010];
int out[100010],q[100010];
int out1[100010];
int main()
{
std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
int m,a,b,c;
cin>>n>>m;
M(head,-1);
while(m--){
cin>>a>>b>>c;
addedge(b,a,c);
out[a]=++out1[a];
}
int s=0,e=-1;
q[++e]=n;
while(s<=e){
s++;
int u=q[s];
for(int i=head[u];i!=-1;i=p[i].next){
int v=p[i].to;
dp[v]+=(dp[u]+p[i].w)/out[v];
if(--out1[v]==0) q[++e]=v;
}
}
cout<<setiosflags(ios::fixed)<<setprecision(2)<<dp[1];
cout<<endl;
return 0;
}
C
C++
C++11
Java
Pascal
Python 2.7
Python 3.3
Ruby
C#
VB.Net
F#
清空代码
TYVJ P1933 绿豆蛙的归宿 题解(未完成)的更多相关文章
- 【BZOJ3036】绿豆蛙的归宿 拓补排序+概率
[BZOJ3036]绿豆蛙的归宿 Description 随着新版百度空间的下线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿. 给出一个有向无环的连通图,起点为1终点为N,每条边都有一个长度. ...
- BZOJ3036: 绿豆蛙的归宿&Wikioi2488:绿豆蛙的归宿
3036: 绿豆蛙的归宿 Time Limit: 2 Sec Memory Limit: 128 MBSubmit: 108 Solved: 73[Submit][Status] Descript ...
- [cogs1065]绿豆蛙的归宿
1065. [Nescafe19] 绿豆蛙的归宿 [题目描述] 给出一个有向无环的连通图,起点为1终点为N,每条边都有一个长度.绿豆蛙从起点出发,走向终点.到达每一个顶点时,如果有K条离开该点的道路, ...
- 2488 绿豆蛙的归宿(拓扑+dp)
488 绿豆蛙的归宿 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 随着新版百度空间的上线,Blog宠物绿豆 ...
- [luogu]P4316 绿豆蛙的归宿(拓扑排序,期望)
P4316 绿豆蛙的归宿 题目背景 随着新版百度空间的上线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿. 题目描述 给出一个有向无环图,起点为1终点为N,每条边都有一个长度,并且从起点出发能够 ...
- 洛谷 P4316 绿豆蛙的归宿
洛谷 P4316 绿豆蛙的归宿 洛谷传送门 题目背景 随着新版百度空间的上线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿. 题目描述 给出一个有向无环图,起点为1终点为N,每条边都有一个长度, ...
- BZOJ 3036: 绿豆蛙的归宿( 期望dp )
从终点往起点倒推 . 在一个图 考虑点 u , 出度为 s : s = 0 , d[ u ] = 0 ; s ≠ 0 , 则 d( u ) = ( ∑ d( v ) ) / s ( ( u , v ) ...
- BZOJ3036绿豆蛙的归宿
BZOJ3036绿豆蛙的归宿 锲下陟凝 褰宓万 郝瓦痕膳 叶诙摞 А知π剧 椐猊∫距 屠缲佗 ゲ蕖揪 俜欧彖鹤 磲砩ほ #琛扶 觅电闸ス 捆鳢げ 浜窠 魂睨"烁 蕞滗浼 洒ヂ跪 ...
- [COGS 1065] 绿豆蛙的归宿
先贴题面w 1065. [Nescafe19] 绿豆蛙的归宿 ★ 输入文件:ldfrog.in 输出文件:ldfrog.out 简单对比时间限制:1 s 内存限制:128 MB 随着新 ...
随机推荐
- c++ primer 10 关联容器
关联容器和顺序容器的本质差别在于:关联容器通过键(key)存储和读取元素,顺序容器则通过元素在容器中的位置顺序存储和访问元素 关联容器类型 map 关联数组:元素通过键来存储和读取 set 大小可变的 ...
- loadrunner乱码问题解决办法
7.LoadRunner回放脚本时,在浏览器显示的中文是乱码 最近,遇到了好多乱码的问题,解决了一些,还有最后一个乱码,能想到的各种办法都试过了,还是不行,很奇怪啊. 解决这些乱码时,涉及到了http ...
- Ubuntu 如何更换阿里源
#进入源地址 cd /etc/apt #备份源文件 sudo cp sources.list sources.list.bak #编辑 sudo vim /etc/apt/sources.list d ...
- linux网络管理----Linux网络配置
1.1 linux配置IP地址 1️⃣ ifconfig命令临时配置IP地址 能不能自动获取IP地址和DNS地址,要看有没有DHCP服务器 win10上,输入ipconfig /all 会看到是否有D ...
- LaTeX算法排版 笔记
方式一 需要包含的 \usepackage[noend]{algpseudocode} \usepackage{algorithmicx,algorithm} 源码 \begin{algorithm} ...
- GenXus进行APP开发-全局颜色设计
我们每次开发APP时,会有不同的全局颜色设计(例如标准控件.状态栏.控件激活时等的默认颜色),那么我们在GeneXus中如何设置这些颜色呢?接下来就给大家介绍一下. 当我们通过GeneXus开发APP ...
- Java_关键字、匿名对象、内部类、访问修饰符、代码块
final关键字 概述: 继承的出现提高了代码的复用性,并方便开发.但随之也有问题,有些类在描述完之后,不想被继承,或者有些类中的部分方法功能是固定的,不想让子类重写.可是当子类继承了这些特殊类之后, ...
- ssm+RESTful bbs项目后端主要设计
小谈: 帖主妥妥的一名"中"白了哈哈哈.软工的大三狗了,也即将找工作,怀着丝丝忐忑接受社会的安排.这是第一次写博客(/汗颜),其实之前在学习探索过程中,走了不少弯路,爬过不少坑.真 ...
- Python协程(上)
几个概念: event_loop 事件循环:程序开启一个无限的循环,程序员会把一些函数注册到事件循环上.当满足事件发生的时候,调用相应的协程函数. coroutine 协程:协程对象,指一个使用asy ...
- luoguP3978 [TJOI2015]概率论 卡特兰数
考虑分别求出$f_n, g_n$表示$n$个点的有根二叉树的数量和$n$个点的所有情况下有根二叉树的叶子结点的总数 有$f_n = \sum_{k} f_k * f_{n - 1 - k}$,因此有$ ...