[cf113d]Museum
传送门
Solution
设一个状态为 \((x,y)\) 表示两人在的位置,求出每个状态期望出现的次数
设一个状态为 \(u\) , \(x_u^0=[u==(a,b)]\)
所以一个状态出现的次数期望为 \(E_u=x_u^0+\sum_vG(v,u)\times E_v\)
其中\(G\)是状态转移的概率矩阵
高消即可,复杂度 \(O(n^6)\)
Code
#include<bits/stdc++.h>
#define ll long long
#define db double
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
inline 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<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*f;
}
const int MN=23;bool A[MN][MN];
int I[MN][MN],N,M,a,b,deg[MN];
db B[MN*MN][MN*MN],F[MN*MN],P[MN];
void Gauss(int n)
{
reg int i,j,k;
for(i=1;i<=n;++i)
{
int p=i;
for(j=i+1;j<=n;++j)if(fabs(B[j][i])>fabs(B[p][i]))p=j;
if(i!=p)swap(B[i],B[p]);
for(j=i+1;j<=n;++j)
{
db d=B[j][i]/B[i][i];
for(k=i;k<=n+1;++k) B[j][k]-=d*B[i][k];
}
}
for(i=n;i;--i)
{
for(j=i+1;j<=n;++j)B[i][n+1]-=F[j]*B[i][j];
F[i]=B[i][n+1]/B[i][i];
}
}
db _(int x,int y){if(!A[x][y])return 0;if(x==y)return P[x];return (1.-P[x])/deg[x];}
int main()
{
reg int i,j,x,y;
N=read(),M=read();a=read(),b=read();
for(i=1;i<=M;++i) x=read(),y=read(),++deg[x],++deg[y],A[x][y]=A[y][x]=1;
for(i=1;i<=N;++i) A[i][i]=1,scanf("%lf",&P[i]);
for(i=1;i<=N;++i)for(j=1;j<=N;++j)I[i][j]=(i-1)*N+j;
B[I[a][b]][N*N+1]=-1.;
for(i=1;i<=N;++i)for(j=1;j<=N;++j)
{
B[I[i][j]][I[i][j]]+=-1.;
if(i!=j)for(x=1;x<=N;++x)for(y=1;y<=N;++y) B[I[x][y]][I[i][j]]+=_(i,x)*_(j,y);
}
Gauss(N*N);
for(i=1;i<=N;++i) printf("%.10lf ",F[I[i][i]]);
return 0;
}
Blog来自PaperCloud,未经允许,请勿转载,TKS!
[cf113d]Museum的更多相关文章
- cf113D. Museum(期望 高斯消元)
题意 题目链接 Sol 设\(f[i][j]\)表示Petya在\(i\),\(Vasya\)在\(j\)的概率,我们要求的是\(f[i][i]\) 直接列方程高斯消元即可,由于每个状态有两维,因此时 ...
- 【CF113D】Museum
Portal --> cf113D Solution 额题意的话大概就是给一个无向图然后两个人给两个出发点,每个点每分钟有\(p[i]\)的概率停留,问这两个人在每个点相遇的概率是多少 如果说我 ...
- Solution -「CF113D」Museum
Upd 2021.10.21 更改了状态定义. 记 \(S(u)\) 表示 \(u\) 结点的相邻结点的集合. 又记 \(p(u)\) 表示走到了 \(u\) 且下一步继续留在 \(u\) 结点的概率 ...
- UVALive 7267 Mysterious Antiques in Sackler Museum (判断长方形)
Sackler Museum of Art and Archaeology at Peking University is located on a beautiful site near the W ...
- Educational Codeforces Round 1 D. Igor In the Museum bfs 并查集
D. Igor In the Museum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598 ...
- Igor In the Museum(搜搜搜151515151515******************************************************1515151515151515151515)
D. Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standar ...
- A. Night at the Museum Round#376 (Div. 2)
A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...
- [codeforces113D]Museum
D. Museum time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input ...
- Codeforces 376A. Night at the Museum
A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- Spring Boot + Vue 前后端分离开发,权限管理的一点思路
在传统的前后端不分的开发中,权限管理主要通过过滤器或者拦截器来进行(权限管理框架本身也是通过过滤器来实现功能),如果用户不具备某一个角色或者某一个权限,则无法访问某一个页面. 但是在前后端分离中,页面 ...
- Prometheus 编写告警规则案例
Prometheus 编写告警规则案例 注:确保alertmanager配置完毕! 1.创建编辑文件:vim /usr/local/prometheus/rules/node.yml # groups ...
- SSM基本配置详解
需要查看SSM基本依赖和完整配置文件的到:SSM基本配置及依赖 示例项目:SSMDemo 1 Spring IOC容器配置 1.1 applicationContext.xml 1.1.1 配置数据源 ...
- C# 中 ==和equals的区别
不想说太多,直接上代码,这两个就没什么联系,有自己独立的规则.联系在一起其实不利于记忆. 下面是测试代码 Console.WriteLine("--equals和==的区别--") ...
- python2.7写的图形密码生成器
#coding:utf8import random,wxdef password(event): a = [chr(i) for i in range(97,123)] b = [chr(i) for ...
- Python Lab Assignments
引用: https://github.com/saismaran33/Python-Lab-Assignments/wiki/Python-Lab-Assignment-2 Lab 1 对于任何Web ...
- FPM十一:点击POPUP显示明细
沿接着前面的Search和List.在LIST中点击一列,弹出窗口显示明细. 1.list中定义事件: METHOD if_fpm_guibb_list~get_definition. DATA:gt ...
- 景点API支持查询携程旅游门票景点详情
门票景点详情,景点api支持查询携程旅游门票景点详情. 接口名称:景点api 接口平台:开放api 接口地址:http://api2.juheapi.com/xiecheng/senicspot/ti ...
- 160--Intersection Of Two Linked List
public class IntersectionOfTwoLinkedList { /* 解法一:暴力遍历求交点. 时间复杂度:O(m*n) 空间复杂度:O(1) */ public ListNod ...
- Linux小知识点
磁盘 Linux的磁盘类型有IDE和SCSI两种. IDE的命名方式是采用/dev/hdx(x代表磁盘块),其下的分区则是/dev/hdxy(y代表该磁盘上的分区号) SCSI则是采用/dev/sdx ...