首页 > 其他分享 >CF605E

CF605E

时间:2024-09-13 20:14:00浏览次数:1  
标签:CF605E int res tot isdigit getchar

题解
总之,赞美太阳

#include <bits/stdc++.h>
using namespace std;
inline int read(){
	char c;int f=1,res=0;
	while(c=getchar(),!isdigit(c))if(c=='-')f*=-1;
	while(isdigit(c))res=res*10+c-'0',c=getchar();
	return res*f;
}
const int N=1e3+5,inf=1e9;
double p[N][N],f[N],g[N],h[N];
int q[N],tot,n;
bool vis[N]; 
inline void upd(){ 
	int j=q[tot];
	for(register int i=1;i<=n;++i){
		if(vis[i])continue;
		g[i]+=f[j]*p[i][j]*h[i];
		h[i]*=1-p[i][j];
		f[i]=g[i]/(1-h[i]);
	}
}
inline void solve(){
	for(register int i=1;i<n;++i)f[i]=g[i]=h[i]=1;
	f[n]=0;h[n]=1;
	vis[n]=true;
	q[++tot]=n;upd();
	while(tot<n){
		int id;double v=inf;
		for(register int i=1;i<=n;++i)if(!vis[i]&&f[i]<v)v=f[i],id=i;
		vis[id]=true;
		q[++tot]=id;upd();
	}
}
int main(){
	n=read();
	if(n==1){return puts("0"),0;}
	for(register int i=1;i<=n;++i)for(register int j=1;j<=n;++j)p[i][j]=read()/100.0;
	solve();
	printf("%.8lf",f[1]);
	return 0;
}

标签:CF605E,int,res,tot,isdigit,getchar
From: https://www.cnblogs.com/zan-mei-tai-yang/p/18412815

相关文章

  • CF605E
    (•̀ω•́)y好fan题解#include<bits/stdc++.h>usingnamespacestd;inlineintread(){ charc;intf=1,res=0; while(c=getchar(),!isdigit(c))if(c=='-')f*=-1; while(isdigit(c))res=res*10+c-'0',c=getchar(); returnres*f;}consti......
  • CF605E Intergalaxy Trips 题解
    Description\(n\)个点的有向完全图。\(i\toj\)的边每天出现的概率均为\(p_{i,j}\),若\(i=j\),有\(p_{i,j}=1\)。每天可以选择一条存在的出边走过去或停留在原地不动。求最优策略下从\(1\)到\(n\)的期望天数。\(n\le10^3\)。Solution设\(f_i\)表示\(i\)......
  • CF605E Intergalaxy Trips
    linkSolution不是很难,不知道为啥之前没做出来。不难看出我们有如下转移式:\[f_{u}=\sumf_{v}\timesP_{u,v}\times(\prod_{f_t<f_v}(1-P_{u,t}))+1\]那么我们可以发......