Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

谁给足测试数据呀!总是经过几百毫秒后WA掉。谢谢!

Posted by jiaohang at 2006-10-14 14:18:36 on Problem 3028
#include<stdio.h>
#include<math.h>
#include<string.h>

int N;
int mark[8192];
float P[13];
float R[13][8192][13];

float A[13][13];
float maxp[13];
int maxn[13];
int next[13],next2[13];

#define cq(a) (left&(~(1<<a)))
#define ck(a) (left&(1<<a))
#define eq(a,b) fabs(a-b)==0

double S(int left,int i,int turn,int aim)
{
	if(i==aim)return 0;
	return R[i][cq(aim)][aim==next[turn]?next2[turn]:next[turn]];
}
	
void G(int left,int n)
{
	if(mark[left])return;
	mark[left]=1;
	if(n==2)
	{
		int a,b;
		a=0;b=0;
		int t=left;
		while(!(t&1))
		{
			++a;
			t>>=1;
		}
		t>>=1;
		b=a;
		while(t)
		{
			++b;
			t>>=1;
		}
		double pp=P[a]+P[b]-P[a]*P[b];
		R[a][left][a]=P[a]/pp;
		R[b][left][a]=(P[b]-P[a]*P[b])/pp;
		R[b][left][b]=P[b]/pp;
		R[a][left][b]=(P[a]-P[a]*P[b])/pp;
		
		return;
	}
	
	for(int i=0;i<N;++i)
	{
		if(ck(i))G(cq(i),n-1);
	}
	
	memset(A,0,sizeof(A));
	
	for(int i=0;i<N;++i)
	{
		if(ck(i))
		{
			for(next[i]=i+1;next[i]!=i;++next[i])
			{
				if(next[i]==N)next[i]=0;
				if(ck(next[i]))break;
			}
			for(next2[i]=next[i]+1;next2[i]!=i;++next2[i])
			{
				if(next2[i]==N)next2[i]=0;
				if(ck(next2[i]))break;
			}
			
			maxp[i]=0;
			maxn[i]=0;
			for(int j=0;j<N;++j)
			{
				if(ck(j)&&j!=i)
				{
					if(S(left,i,i,j)>maxp[i])
					{
						maxp[i]=S(left,i,i,j);
						maxn[i]=1;
					}
					else if(eq(S(left,i,i,j),maxp[i]))
						maxn[i]++;
				}
			}
			for(int j=0;j<N;++j)
			{
				if(ck(j) && j!=i && eq(S(left,i,i,j),maxp[i]))
				{
					for(int k=0;k<N;++k)
						if(ck(k) && j!=k)
						{
							A[k][i]+=P[i]*S(left,k,i,j)/maxn[i];
						}
				}
			}
		}
	}
	
	for(int i=0;i<N;++i)
	{
		if(ck(i))
		{
			double PP=1-P[i];
			int last;
			R[i][left][i]=A[i][i];
			for(int j=next[i];j!=i;)
			{

				if(ck(j))
				{
					R[i][left][i]+=PP*A[i][j];
					PP*=1-P[j];
					last=j;
				}
				++j;
				if(j==N)j=0;
			}
			R[i][left][i]/=1-PP;
			
			PP=R[i][left][i];
			for(int j=last;j!=i;)
			{
				if(ck(j))
					PP=R[i][left][j]=(1-P[j])*PP+A[i][j];
				--j;
				if(j==-1)j=N-1;
			}
			
		}
	}
				
				
	
	
}



int main()
{
	int TT;
	scanf("%d",&TT);
	for(int TTT=0;TTT<TT;++TTT)
	{
		scanf("%d",&N);
		int t;
		for(int i=0;i<N;++i)
		{
			scanf("%d",&t);
			P[i]=t/100.0;
		}
		memset(mark,0,sizeof(mark));
		G((1<<N)-1,N);
		for(int i=0;i<N;++i)
		{
			printf ("%.2f ",100*R[i][(1<<N)-1][0]);
		}
		printf("\n");
		
	}
	return 0;
}
		

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator