其他分享
首页 > 其他分享> > 20210524考试—景区路线规划题解

20210524考试—景区路线规划题解

作者:互联网

考场上爆搜的每个点到达的概率,\(TLE\)理所当然,由于搜概率不太好记忆化,所以这个方法可能也只能到这了

code


#include <cstdio>
#include <cstring>
#include <algorithm>
#define printf Ruusupuu=printf
#define R register int
#define int long long

using namespace std ;
const int N = 3e2 + 10 ;
typedef long long L ;
typedef double D ;

inline int read(){
	int w = 0 ; bool fg = 0 ; char ch = getchar() ;
	while( ch < '0' || ch > '9' ) fg |= ( ch == '-' ) , ch = getchar() ;
	while( ch >= '0' && ch <= '9' ) w = ( w << 1 ) + ( w << 3 ) + ( ch - '0' ) , ch = getchar() ;
	return fg ? -w : w ;
}

int Ruusupuu , n , m , k , cnt , head [N] , xs , ys , ws ;
struct P{ int c , h1 , h2 ; D p ; } b [N] ;
struct E{ int fr , to , next , w ; } a [N << 6] ;
D ans1 , ans2 ;

inline void add( int f , int t , int w ){
	a [++ cnt].fr = f ;
	a [cnt].to = t ;
	a [cnt].w = w ; 
	a [cnt].next = head [f] ;
	head [f] = cnt ;
}

inline void dfs( int x , int lef , D p ){
//	printf( "THIS DFS%ld %ld\n" , x , lef ) ;
	b [x].p += p ; 
	int gnt = 0 ;
	for( R i = head [x] ; ~i ; i = a [i].next ){
		int y = a [i].to ;	
//		printf( "%ld %ld %ld %ld\n" , x , y , lef , lef - a [i].w - b [y].c ) ;
		if( lef - a [i].w - b [y].c >= 0 ) gnt ++ ;
	}
	for( R i = head [x] ; ~i ; i = a [i].next ){
		int y = a [i].to ;
		if( lef - a [i].w - b [y].c >= 0 )
		 dfs( y , lef - a [i].w - b [y].c , p / (D) gnt ) ;  
	}
}

void sc(){
	n = read() , m = read() , k = read() ; memset( head , -1 , sizeof( head ) ) ;
	for( R i = 1 ; i <= n ; i ++ ) b [i].c = read() , b [i].h1 = read() , b [i].h2 = read() ;
	for( R i = 1 ; i <= m ; i ++ ) xs = read() , ys = read() , ws = read() , add( xs , ys , ws ) , add( ys , xs , ws ) ;
} 

void work(){
	for( R i = 1 ; i <= n ; i ++ ) dfs( i , k - b [i].c , 1.0 / (D) n ) ; 
	for( R i = 1 ; i <= n ; i ++ ) ans1 += (D) b [i].h1 * b [i].p , ans2 += (D) b [i].h2 * b [i].p ;
	printf( "%.5lf %.5lf\n" , ans1 , ans2 ) ;
}

signed main(){
	sc() ;
	work() ;
	return 0 ; 
}

这个题正解方法很多,一种一种写
1.求期望

思路:直接设数组\(f[i][j]\)为在\(j\)时间处于\(i\)点时候,从此刻到游戏结束开心程度的期望,那么答案只需要把\(f[i][0]\)都加起来在除以\(n\)。

对这个答案的理解就是把从每个点开始游戏的开心期望加起来再除以\(n\),由于从每个点开始游玩的概率是相等的,所以要除以一个\(n\)。

式子很好推\(f[i][j]= \sum f[g][j-w[i,j]-t[g]](if(j>=w[i,j]+t[g]))\)

标签:ch,int,题解,20210524,long,read,景区,include,define
来源: https://www.cnblogs.com/TYubai/p/14812922.html