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

可耻的贴代码

Posted by songruirui at 2013-03-30 11:43:00 on Problem 1322
#include <iostream>
#include <memory.h>
#include <cstdio>
using namespace std;
float p[3][160];//每次算完第i行,就把第i-1行换掉
int C,N,M;//c:颜色数,N:总共拿球次数,M:最后剩下颜色数

float findre()
{
	memset(p,0,sizeof(p));
	p[0][0]=1;
	for(int i=1;i<=N;i++)
	{
		for(int j=0;j<=C+1;j++)
		{
			p[i%2][j]=p[(i-1)%2][j-1]*(C-j+1)/C;
			p[i%2][j]+=p[(i-1)%2][j+1]*(j+1)/C;
		}
		for(int j=0;j<=C+1;j++)
		{
			p[(i-1)%2][j]=p[i%2][j];
		}
	}
	return p[N%2][M];
}
int main()
{
		
	cin>>C;
	while(C!=0)
	{
		cin>>N>>M;
		if(N>1000)
			N=1000+N%2;
		float result;
		if(M>C)
			result=0;
		else
			result=findre();
		printf("%.3f\n",result);
		cin>>C;
	}
	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