【Codeforces】113 D. Museum
题解
我们设\(f(i,j)\)是\((i,j)\)这个点期望被经过多少次
我们可以列出方程组来消元,由于终点只会被经过0次或者1次,期望就是概率
对于起点的话我们期望经过次数多加一个1
复杂度\(O(n^6)\)
代码
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
//#define ivorysi
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mo 974711
#define RG register
#define MAXN 200005
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) putchar('-'),x = -x;
if(x >= 10) out(x / 10);
putchar('0' + x % 10);
}
int g[25][25],ind[25];
int N,M,a,b;
db P[25],f[505][505],ans[505];
int get_id(int x,int y) {
return (x - 1) * N + y;
}
void Guass() {
int T = N * N;
for(int i = 1 ; i <= T ; ++i) {
int l = i;
for(int j = i ; j <= T ; ++j) if(fabs(f[l][i]) < fabs(f[j][i])) l = j;
if(l != i) {
for(int j = 1 ; j <= T ; ++j) swap(f[l][j],f[i][j]);
}
for(int j = i + 1 ; j <= T ; ++j) {
db t = f[j][i] / f[i][i];
for(int k = i ; k <= T + 1; ++k) {
f[j][k] -= t * f[i][k];
}
}
}
for(int i = T ; i >= 1 ; --i) {
for(int j = i + 1 ; j <= T ; ++j) {
f[i][T + 1] -= f[i][j] * ans[j];
}
ans[i] = f[i][T + 1] / f[i][i];
}
}
void Solve() {
read(N);read(M);read(a);read(b);
int u,v;
for(int i = 1 ; i <= M ; ++i) {
read(u);read(v);
ind[u]++;ind[v]++;
g[u][v] = g[v][u] = 1;
}
for(int i = 1 ; i <= N ; ++i) scanf("%lf",&P[i]);
for(int i = 1 ; i <= N ; ++i) {
for(int j = 1 ; j <= N ; ++j) {
int t = get_id(i,j);
if(i == a && j == b) f[t][N * N + 1] += 1.0;
f[t][t] += 1.0;
for(int k = 1 ; k <= N ; ++k) {
if(k != i && !g[i][k]) continue;
for(int h = 1 ; h <= N ; ++h) {
if(j != h && !g[j][h]) continue;
if(k == h) continue;
db tmp = 1.0;
if(i == k) tmp *= P[i];
else tmp *= (1 - P[k]) / ind[k];
if(j == h) tmp *= P[h];
else tmp *= (1 - P[h]) / ind[h];
f[t][get_id(k,h)] += -tmp;
}
}
}
}
Guass();
for(int i = 1 ; i <= N ; ++i) {
printf("%.8lf ",ans[get_id(i,i)]);
}
enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
【Codeforces】113 D. Museum的更多相关文章
- 【Codeforces】Round #491 (Div. 2) 总结
[Codeforces]Round #491 (Div. 2) 总结 这次尴尬了,D题fst,E没有做出来.... 不过还好,rating只掉了30,总体来说比较不稳,下次加油 A:If at fir ...
- 【Codeforces】Round #488 (Div. 2) 总结
[Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...
- 【LeetCode】113. Path Sum II 解题报告(Python)
[LeetCode]113. Path Sum II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fu ...
- 【CodeForces】601 D. Acyclic Organic Compounds
[题目]D. Acyclic Organic Compounds [题意]给定一棵带点权树,每个点有一个字符,定义一个结点的字符串数为往下延伸能得到的不重复字符串数,求min(点权+字符串数),n&l ...
- 【Codeforces】849D. Rooter's Song
[算法]模拟 [题意]http://codeforces.com/contest/849/problem/D 给定n个点从x轴或y轴的位置p时间t出发,相遇后按对方路径走,问每个数字撞到墙的位置.(还 ...
- 【CodeForces】983 E. NN country 树上倍增+二维数点
[题目]E. NN country [题意]给定n个点的树和m条链,q次询问一条链(a,b)最少被多少条给定的链覆盖.\(n,m,q \leq 2*10^5\). [算法]树上倍增+二维数点(树状数组 ...
- 【CodeForces】925 C.Big Secret 异或
[题目]C.Big Secret [题意]给定数组b,求重排列b数组使其前缀异或和数组a单调递增.\(n \leq 10^5,1 \leq b_i \leq 2^{60}\). [算法]异或 为了拆位 ...
- 【CodeForces】700 D. Huffman Coding on Segment 哈夫曼树+莫队+分块
[题目]D. Huffman Coding on Segment [题意]给定n个数字,m次询问区间[l,r]的数字的哈夫曼编码总长.1<=n,m,ai<=10^5. [算法]哈夫曼树+莫 ...
- 【CodeForces】906 D. Power Tower 扩展欧拉定理
[题目]D. Power Tower [题意]给定长度为n的正整数序列和模数m,q次询问区间[l,r]累乘幂%m的答案.n,q<=10^5,m,ai<=10^9. [算法]扩展欧拉定理 [ ...
随机推荐
- 在MySQL或者SQLServer中,添加对象后自动返回主键到对象模型中的配置方式
设置是否使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中.MySQL和SQLServer执行auto-generated key fiel ...
- Kafka 0.8 Consumer处理逻辑
0.前言 客户端用法: kafka.javaapi.consumer.ConsumerConnector consumer = kafka.consumer.Consumer.createJavaCo ...
- Ubuntu 14.04安装和3556sdk环境配置
1.配置为固定ip: vi /etc/network/interfaces 最后添加 iface eth0 inet staticaddress 192.168.1.100netmask 255.25 ...
- bzoj千题计划135:bzoj1066: [SCOI2007]蜥蜴
http://www.lydsy.com/JudgeOnline/problem.php?id=1066 每个柱子拆成两个点 i<<1,i<<1|1,之间连流量为高度的边 如果 ...
- JavaScript 生成n位随机数
function RndNum(n){ var rnd=""; for(var i=0;i<n;i++) rnd+=Math.floor(Math.random()*10); ...
- windows下自动启动Redis隐藏命令行窗口
这段时间看了看关于Redis的相关内容,对于Redis在windows下的安装和常规启动我就不多说了.可以参考其他的博客http://www.cnblogs.com/edisonchou/p/3821 ...
- 网页实战开发笔记之——最全面的HTML的头部信息介绍
HTML中我们一般把<head></head>部分称为网页的头部.头部部分的内容虽然不会在页面中显示,但它能影响到搜索引擎对网页的收录和排序,以及网页的各种全局设置,可以说是至 ...
- Struts S2-052漏洞利用之Meterpreter(CVE-2017-9805)
Struts S2-052漏洞爆出来已经快一周了,大家可能更想知道其危害~鸡肋? 这里就直接给出漏洞利用拿Meterpreter的过程,想了解更多的请参考其他文章,下面是实验演示部分.Struts S ...
- 系统学习(javascript)_基础(语法)
1.分类 ECMAScript javascript的标准 DOM Document object Model文档对象模型 BOM Browser object Model 浏览器对象模型 ti ...
- MySQL5.7之多源复制&Nginx中间件(下)【转】
有生之年系列----MySQL5.7之多源复制&Nginx中间件(下)-wangwenan6-ITPUB博客http://blog.itpub.net/29510932/viewspace-1 ...