zoukankan      html  css  js  c++  java
  • Bzoj1415: [Noi2005]聪聪和可可

    题面

    Bzoj

    Sol

    就是求期望
    预处理出可可在某一位置时聪聪下一步怎么走
    然后按题意模拟,记搜

    # include <bits/stdc++.h>
    # define RG register
    # define IL inline
    # define Fill(a, b) memset(a, b, sizeof(a))
    using namespace std;
    typedef long long ll;
    const int _(2005);
    
    IL ll Input(){
        RG ll x = 0, z = 1; RG char c = getchar();
        for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
        for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
        return x * z;
    }
    
    int n, m, fst[_], nxt[_], to[_], cnt, dis[_], pre[_][_], deg[_];
    bool vis[_], G[_][_];
    double f[_][_];
    queue <int> Q;
    
    IL void Add(RG int u, RG int v){
    	to[cnt] = v; nxt[cnt] = fst[u]; fst[u] = cnt++; ++deg[v];
    }
    
    IL void Bfs(RG int S){
    	dis[S] = 0; Fill(vis, 0); vis[S] = 1; Q.push(S);
    	while(!Q.empty()){
    		RG int u = Q.front(); Q.pop();
    		for(RG int e = fst[u]; e != -1; e = nxt[e]){
    			if(vis[to[e]]) continue;
    			dis[to[e]] = dis[u] + 1;
    			vis[to[e]] = 1; Q.push(to[e]);
    		}
    	}
    	for(RG int i = 1; i <= n; ++i)
    		for(RG int e = fst[i]; e != -1; e = nxt[e]){
    			if(dis[to[e]] + 1 != dis[i]) continue;
    			if(!pre[S][i]) pre[S][i] = to[e];
    			else pre[S][i] = min(pre[S][i], to[e]);
    		}
    }
    
    IL double Dfs(RG int A, RG int B){
    	if(G[A][B]) return f[A][B];
    	G[A][B] = 1; RG int nt = pre[B][A];
    	if(A == B) return f[A][B] = 0;
    	if(nt == B || pre[B][nt] == B) return f[A][B] = 1;
    	nt = pre[B][nt]; f[A][B] = Dfs(nt, B);
    	for(RG int e = fst[B]; e != -1; e = nxt[e])	f[A][B] += Dfs(nt, to[e]);
    	f[A][B] = f[A][B] / (deg[B] + 1) + 1;
    	return f[A][B];
    }
    
    int main(RG int argc, RG char* argv[]){
    	n = Input(); m = Input(); Fill(fst, -1);
    	RG int A = Input(), B = Input();
    	for(RG int i = 1; i <= m; ++i){
    		RG int u = Input(), v = Input();
    		Add(u, v); Add(v, u);
    	}
    	for(RG int i = 1; i <= n; ++i) Bfs(i);
    	printf("%.3lf
    ", Dfs(A, B));
    	return 0;
    }
    
  • 相关阅读:
    使用别名(CName)记录免费将顶级域名解析到动态IP上
    DataTable 排序
    VS2005中使用MySQL 5.0
    让VS2005用起来更顺手
    PowerBuilder 9.0 Datawindow 导出 pdf 文件
    使用WebClient自动填写并提交ASP.NET页面表单的源代码
    C#中使用条件运算符 (?:)
    如何申请 @msn.com 邮箱
    遇上你是我的缘[转]
    Linux也玩远程桌面(VNC)
  • 原文地址:https://www.cnblogs.com/cjoieryl/p/8424091.html
Copyright © 2011-2022 走看看