跟那个某省省选题(具体忘了)游走差不多...

把边搞到点上然后按套路Gauss即可

貌似有人说卡精度,$eps≤1e-13$,然而我$1e-12$也可以过...

代码:

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#define writeln(x) write(x),puts("")
#define writep(x) write(x),putchar(' ')
using namespace std;
inline int read(){
int ans=,f=;char chr=getchar();
while(!isdigit(chr)){if(chr=='-') f=-;chr=getchar();}
while(isdigit(chr)){ans=(ans<<)+(ans<<)+chr-;chr=getchar();}
return ans*f;
}void write(int x){
if(x<) putchar('-'),x=-x;
if(x>) write(x/);
putchar(x%+'');
}const int M = ;
int n,m,p,q,du[M],e[M][M];
double a[M][M],ans[M],b[M];
const double eps=1e-;
inline void Gauss(){
for(int i=;i<=n;i++){
int maxn=i;
for(int j=i+;j<=n;j++) if(fabs(a[j][i]-a[maxn][i])<eps) maxn=j;
for(int j=;j<=n+;j++) swap(a[maxn][j],a[i][j]);
for(int j=n+;j>=i;j--)
for(int k=i+;k<=n;k++)
a[k][j]-=a[k][i]/a[i][i]*a[i][j];
}
for(int i=n;i>=;i--){
for(int j=i+;j<=n;j++)
a[i][n+]-=a[j][n+]*a[i][j];
a[i][n+]/=a[i][i];
}
for(int i=;i<=n;i++) ans[i]=a[i][n+];
}
int main(){
n=read(),m=read(),p=read(),q=read();
const double ps=p*1.0/q;
for(int i=;i<=m;i++){
int x=read(),y=read();
e[x][y]=e[y][x]=;
du[x]++,du[y]++;
}
for(int i=;i<=n;i++){
a[i][i]=1.0;
for(int j=;j<=n;j++)
if(e[i][j])
a[i][j]-=(1.0-ps)/du[j];
}
a[][n+]=1.0;
Gauss();
for(int i=;i<=n;i++)printf("%.9lf\n",ans[i]*ps);
return ;
}

P2973 [USACO10HOL]赶小猪的更多相关文章

  1. 洛谷P2973 [USACO10HOL]赶小猪

    https://www.luogu.org/problemnew/show/P2973 dp一遍,\(f_i=\sum_{edge(i,j)}\frac{f_j\times(1-\frac{P}{Q} ...

  2. 洛谷P2973 [USACO10HOL]赶小猪(高斯消元 期望)

    题意 题目链接 Sol 设\(f[i]\)表示炸弹到达\(i\)这个点的概率,转移的时候考虑从哪个点转移而来 \(f[i] = \sum_{\frac{f(j) * (1 - \frac{p}{q}) ...

  3. Luogu P2973 [USACO10HOL]赶小猪Driving Out the Piggi 后效性DP

    有后效性的DP:$f[u]$表示到$u$的期望次数,$f[u]=\Sigma_{(u,v)} (1-\frac{p}{q})*f[v]*deg[v]$,最后答案就是$f[u]*p/q$ 刚开始$f[1 ...

  4. [Luogu2973][USACO10HOL]赶小猪

    Luogu sol 首先解释一波这道题无重边无自环 设\(f_i\)表示\(i\)点上面的答案. 方程 \[f_u=\sum_{v,(u,v)\in E}(1-\frac PQ)\frac{f_v}{ ...

  5. Luogu2973:[USACO10HOL]赶小猪

    题面 Luogu Sol 设\(f[i]\)表示炸弹到\(i\)不爆炸的期望 高斯消元即可 另外,题目中的概率\(p/q\)实际上为\(1-p/q\) 还有,谁能告诉我不加\(EPS\),为什么会输出 ...

  6. 洛谷2973 [USACO10HOL]赶小猪Driving Out the Piggi… 概率 高斯消元

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - 洛谷2973 题意概括 有N个城市,M条双向道路组成的地图,城市标号为1到N.“西瓜炸弹”放在1号城市,保证城 ...

  7. [Luogu2973][USACO10HOL]赶小猪Driving Out the Piggi…

    题目描述 The Cows have constructed a randomized stink bomb for the purpose of driving away the Piggies. ...

  8. [USACO10HOL]赶小猪

    嘟嘟嘟 这题和某一类概率题一样,大体思路都是高斯消元解方程. 不过关键还是状态得想明白.刚开始令\(f[i]\)表示炸弹在点\(i\)爆的概率,然后发现这东西根本无法转移(或者说概率本来就是\(\fr ...

  9. luogu P2973 [USACO10HOL]Driving Out the Piggies G 驱逐猪猡

    luogu LINK:驱逐猪猡 bzoj LINK:猪猪快跑 问题是在1时刻有个炸蛋在1号点 这个炸弹有p/q的概率爆炸 如果没有爆炸 那么会有1/di的概率选择一条边跳到另外一个点上重复这个过程. ...

随机推荐

  1. HDU1241&POJ2386 dfs简单题

    2道题目都差不多,就是问和相邻所有点都有相同数据相连的作为一个联通快,问有多少个连通块 因为最近对搜索题目很是畏惧,总是需要看别人代码才能上手,就先拿这两道简单的dfs题目来练练手,顺便理一理dfs的 ...

  2. [luoguP1022] 计算器的改良(模拟)

    传送门 超级大模拟.. 代码 #include <cstdio> #include <cstring> #include <iostream> #define is ...

  3. Flask(2):登陆验证

    装饰器补充: import functools def auth(func): @functools.wraps(func) # 作用:把原函数的原信息封装到 inner 中 def inner(*a ...

  4. struts2开发action 的三种方法以及通配符、路径匹配原则、常量

    struts2开发action 的三种方法 1.继承ActionSupport public class UserAction extends ActionSupport { // Action中业务 ...

  5. Codeforces 629D Babaei and Birthday Cake(树状数组优化dp)

    题意: 线段树做法 分析: 因为每次都是在当前位置的前缀区间查询最大值,所以可以直接用树状数组优化.比线段树快了12ms~ 代码: #include<cstdio> #include< ...

  6. Tomcat服务器调优

    一,目标:优化tomcat来提高访问的并发能力. 服务器提供的内存,cpu,以及硬盘的性能对数据的处理起决定性作用. tomcat的3种运行模式 tomcat的运行模式有3种: 1. bio默认的模式 ...

  7. Jmeter执行java脚本结束时提示:The JVM should have exited but did not.

    使用jmeter对dubbo进行压测时,需要使用jmeter的sampler里的java请求 使用./jmeter.sh -n -t test.jmx -l test.jmx -o -e test后台 ...

  8. Samba完整篇 ubuntu 10.04

    基本的服务器准备工作 修改Root密码 sudo passwd root 在提示下建立新密码 修改静态IP: sudo gedit /etc/network/interfaces   #网络配置文件 ...

  9. 改动Centosserver主机名称

    1.暂时改动server主机名称: hostname myhost. myhost为你指定的主机名称. 2.永久性的改动主机名称 Centosserver安装好之后.默认的主机名为:localhost ...

  10. chorme requestBody

    https://stackoverflow.com/questions/18534771/chrome-extension-how-to-get-http-response-body Chrome w ...