France '98

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=30506#problem/H

 

#include<map>

#include<set>

#include<list>

#include<cmath>

#include<ctime>

#include<deque>

#include<stack>

#include<bitset>

#include<cstdio>

#include<vector>

#include<cstdlib>

#include<cstring>

#include<iomanip>

#include<numeric>

#include<sstream>

#include<utility>

#include<iostream>

#include<algorithm>

#include<functional>



using namespace std ;

char str[ 20 ][ 50 ] ;

double val[ 20 ][ 20 ] ;

double dp[ 20 ][ 5 ] ;

 

int main()

{

	for( int i = 0 ; i < 16 ; ++i )

	{

		scanf( "%s" , str[ i ] ) ;

	}

	for( int i = 0 ; i < 16 ; ++i )

	{

		for( int j = 0 ; j < 16 ; ++j )

		{

			scanf( "%lf" , &val[ i ][ j ] ) ;

			val[ i ][ j ] /= 100 ;

		}

	}

	memset( dp , 0 , sizeof( dp ) ) ;

	for( int i = 0 ; i < 16 ; ++i )

	{

		dp[ i ][ 0 ] = 1 ;

	}

	int len = 1 ;

	for( int i = 1 ; i <= 4 ; ++i )

	{

	

		for( int j = 0 ; j < 16 ; ++j )

		{	

			int st ;

			if( ( j / len ) & 1 )

			{

				st = ( j / len - 1 ) * len ;

			}

			else

			{

				st = ( j / len + 1 ) * len ;

			}

			

			for( int k = st ; k < st + len ; ++k )

			{

				dp[ j ][ i ] += dp[ j ][ i - 1 ] * dp[ k ][ i - 1 ] * val[ j ][ k ] ;

			}

		}

		len = len * 2 ;

	}

	for( int i = 0 ; i < 16 ; ++i )

	{

		printf( "%-11sp=%.2lf%%\n" , str[ i ] , dp[ i ][ 4 ]* 100 ) ; 

	}

	//system( "pause" ) ;

    return 0;

}


 

 

你可能感兴趣的:(c)