这题概率dp + 拓扑排序可以写

改天补解释

#include <bits/stdc++.h>
using namespace std; const int maxn=1e5+10;
vector<int>vec[maxn];
int indeg[maxn],seq[maxn];
double d[maxn],f[maxn];
int N,M,T,tot=0; void topo()
{
queue<int>q;
q.push(1);
tot=0;
seq[tot++]=1;
while (!q.empty()) {
int u=q.front();
q.pop();
for (int i=0;i<vec[u].size();i++) {
if (--indeg[vec[u][i]]==0) {
q.push(vec[u][i]);
seq[tot++]=vec[u][i];
}
}
}
} int main()
{
scanf("%d",&T);
while (T--) {
scanf("%d%d",&N,&M);
for (int i=1;i<=N;i++) {
vec[i].clear();
}
memset(indeg,0,sizeof(indeg));
for (int i=0;i<=N;i++) {
d[i]=0;
f[i]=0;
}
int x,y;
for(int i=0;i<M;i++) {
scanf("%d%d",&x,&y);
vec[x].push_back(y);
indeg[y]++;
}
topo();
for (int i=tot-2;i>=0;i--) {
int u=seq[i];
int cnt=vec[u].size()+1;
for (int j=0;j<cnt-1;j++) {
d[u]+=d[vec[u][j]];
}
d[u]=(d[u]/(double)cnt+1)*(double)cnt/(double)(cnt-1);
}
for (int i=tot-2;i>=0;i--) {
int u=seq[i];
int cnt=vec[u].size()+1;
for (int j=0;j<cnt-1;j++) {
f[u]+=f[vec[u][j]];
}
f[u]+=cnt*d[u];
f[u]=f[u]/(double)(cnt-1);
}
printf("%.2lf\n",f[1]);
}
return 0;
}

The Preliminary Contest for ICPC Asia Nanjing 2019 - D Robots(概率dp+拓扑排序)的更多相关文章

  1. The Preliminary Contest for ICPC Asia Nanjing 2019 D. Robots

    题意:给出一个DAG,一只机器人从1点出发,等概率地选择一条出边走或者停留在原点,机器人的第k次行动消耗能量是k(无论是走还是停留都算一次行动).问1到n的期望. 解法:因为行动消耗的能量跟行动次数有 ...

  2. The Preliminary Contest for ICPC Asia Nanjing 2019/2019南京网络赛——题解

    (施工中……已更新DF) 比赛传送门:https://www.jisuanke.com/contest/3004 D. Robots(期望dp) 题意 给一个DAG,保证入度为$0$的点只有$1$,出 ...

  3. [The Preliminary Contest for ICPC Asia Nanjing 2019] A-The beautiful values of the palace(二维偏序+思维)

    >传送门< 前言 这题比赛的时候觉得能做,硬是怼了一个半小时,最后还是放弃了.开始想到用二维前缀和,结果$n\leq 10^{6}$时间和空间上都爆了,没有办法.赛后看题解用树状数组,一看 ...

  4. 计蒜客 The Preliminary Contest for ICPC Asia Nanjing 2019

    F    Greedy Sequence You're given a permutation aa of length nn (1 \le n \le 10^51≤n≤105). For each  ...

  5. The Preliminary Contest for ICPC Asia Nanjing 2019

    传送门 A. The beautiful values of the palace 题意: 给出一个\(n*n\)的矩阵,并满足\(n\)为奇数,矩阵中的数从右上角开始往下,类似于蛇形填数那样来填充. ...

  6. The Preliminary Contest for ICPC Asia Nanjing 2019 H. Holy Grail

    题目链接:https://nanti.jisuanke.com/t/41305 题目说的很明白...只需要反向跑spfa然后输入-dis,然后添-dis的一条边就好了... #include < ...

  7. The Preliminary Contest for ICPC Asia Nanjing 2019 B. super_log (广义欧拉降幂)

    In Complexity theory, some functions are nearly O(1)O(1), but it is greater then O(1)O(1). For examp ...

  8. 树状数组+二维前缀和(A.The beautiful values of the palace)--The Preliminary Contest for ICPC Asia Nanjing 2019

    题意: 给你螺旋型的矩阵,告诉你那几个点有值,问你某一个矩阵区间的和是多少. 思路: 以后记住:二维前缀和sort+树状数组就行了!!!. #define IOS ios_base::sync_wit ...

  9. B.super_log(The Preliminary Contest for ICPC Asia Nanjing 2019)

    同:https://www.cnblogs.com/--HPY-7m/p/11444923.html #define IOS ios_base::sync_with_stdio(0); cin.tie ...

随机推荐

  1. 如何删除github中的repository

    打开个人界面->点击进入想删除的repository的界面->拉到最下面的danger zone->delete

  2. codeforces Codeforces Round #597 (Div. 2) B. Restricted RPS 暴力模拟

    #include <bits/stdc++.h> using namespace std; typedef long long ll; ]; ]; int main() { int t; ...

  3. 题解【POJ1160】Post Office

    [POJ1160]Post Office Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22362 Accepted: 1208 ...

  4. Golang利用第三方包获取本机cpu使用率以及内存使用情况

    第三方包下载 $ github.com/shirou/gopsutil 获取内存方面的信息 package main import ( "fmt" "github.com ...

  5. VS2017 + Windows10编译C++ MongoDB驱动

    转载地址:https://blog.csdn.net/sqcfj/article/details/86716831 mongoDB有两个接口库:mongo-c-driver和mongo-cxx-dri ...

  6. 关于Ajax请求的JS封装函数

    每次连接ajax都要重复写很多代码,所以写了一个JS封装函数,如下: 再来解释一下其中obj对象的参数形式: obj={ 'type':提交方式,    get/post 'url' : 提交地址, ...

  7. 搭建Hexo一键生成,同步部署

    全网最全小白搭建Hexo+Gitee/Coding/Github 全网最全小白搭建Hexo+Gitee/Coding/Github 本站内容已全部转移到https://www.myyuns.ltd,具 ...

  8. Python(二):做题函数记录

    一,10进制 转 2,8,16进制 bin(<int>) ,oct(<int>),hex(<int>) 输出示例 '0b10011010010' '0o2322' ...

  9. oracle建表时出现“标识符无效”错误

    oracle用以下sql语句新建表时,出现"标识符无效"错误: create table users( user_id integer not null, user_name va ...

  10. Python 多任务(进程) day1(3)

    进程间的通信 可以用socket进行进程间的通信 可以用同意文件来进行通信(但是在硬盘上读取和写入比较慢,内存运行太快了) Queue队列(记得是队列)  在同一内存中通信 因为进程之间不能共享全局变 ...