# BZOJ 3270

## 3270: 博物馆

Time Limit: 30 Sec  Memory Limit: 128 MB
Submit: 750  Solved: 409
[Submit][Status][Discuss]

2 1 1 2
1 2
0.5
0.5

## Sample Output

0.500000 0.500000

## Source

f(i,j)=f(i,j)pipj+(i,x),(j,y)Ef(x,j)pjgox+f(i,y)pigoy+f(x,y)goxgoyf(i,j)=f(i,j)pipj+∑(i,x),(j,y)∈Ef(x,j)pjgox+f(i,y)pigoy+f(x,y)goxgoy

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define eps 1e-8
#define N 25
#define ll long long
#define p(x,y) (x-1)*n+y
using namespace std;
{
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,next;}g[N<<4];
int n,m,A,B,tot,d[N];
double a[N*N][N*N],p[N];

void print()
{
printf("-------------\n");
for(int i=1;i<=tot;i++)
{
for(int j=1;j<=tot+1;j++)printf("%.2lf ",a[i][j]);
printf("\n");
}
}

void build(int x,int y)
{
a[p(x,y)][p(x,y)]--;
{
int u=g[i].to,v=g[j].to;
if(u!=v)
{
int t1=p(x,y),t2=p(u,v);
if(u==x && v==y)a[t1][t2]+=(p[u]*p[v]);
else if(u==x)a[t1][t2]+=(p[u]*(1-p[v])/d[v]);
else if(v==y)a[t1][t2]+=(p[v]*(1-p[u])/d[u]);
else a[t1][t2]+=((1-p[u])*(1-p[v])/(d[u]*d[v]));
}
}
}
void gauss()
{
for(int i=1;i<=tot;i++)
{
int j;
for(j=i;j<=tot;j++)if(fabs(a[j][i])>eps)break;

//print();
for(int k=1;k<=tot+1;k++)swap(a[j][k],a[i][k]);

//print();

for(int j=1;j<=tot;j++)
if(j!=i)
{
double t=a[j][i]/a[i][i];
for(int k=1;k<=tot+1;k++)a[j][k]-=(t*a[i][k]);
}

}
}

int main()
{
tot=n*n; a[p(A,B)][tot+1]=-1;
for(int i=1;i<=m;i++)
{
d[x]++;d[y]++;
}
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++)
build(i,j);
//print();
gauss();
//print();
for(int i=1;i<=n;i++)
{
int t=p(i,i);
printf("%.6lf",a[t][tot+1]/a[t][t]);
if(i!=n)printf(" ");
}
return 0;
}

posted @ 2018-04-07 00:17  hyf20010101  阅读(...)  评论(... 编辑 收藏