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 mkss at 2004-09-06 21:17:57 on Problem 1322
#include<iostream>
#include<math.h>

using namespace std;

double array[110][2];

double backup[110];

long c, m, n;
solve()
{
	long i, j;
	bool f;

	i = 1;
	while(n--)
	{
		if(i == 0)
		{
			array[i+1][1] += array[i][0] * (1.0 - (double)((double)i/(double)c));
			i+=2;
		}

		for(;i < c;i+=2)
		{
			array[i-1][1] += array[i][0] * (double)((double)i/(double)c);
			array[i+1][1] += array[i][0] * (1.0 - (double)((double)i/(double)c));
		}

		if(i == c)
		{
			array[i-1][1] += array[i][0] * (double)((double)i/(double)c);
		}

		for(j = 0;j <=c; j++)
		{
			if(fabs(backup[j] - array[j][1]) >= 0.0005)
				break;
		}

		if(j > c)
		{
		/*	for(j = 0;j <= c;j++)
			{
				array[j][0] = array[j][1];
			}
*/
			return;
		}
//		else
//		{
//			cout << "BACK:" << backup[j] << " ARRAY[1]:" << array[j][1] << endl;
//		}


//		cout << "N=" << n << endl;

		for(j = 0;j <= c;j++)
		{
			backup[j] = array[j][0];
			array[j][0] = array[j][1];
			array[j][1] = 0.0;

//			cout << array[j][0] << ' ';
		}
//		cout << endl;

		if(i % 2 == 1)
			i = 0;
		else
			i = 1;
		
	}
	n = 1;
}

main()
{
	long i, j;

	while(1)
	{
	cin >> c;

	if(c == 0)
		return;

	cin >> n >> m;

		cout.setf(ios_base::fixed, ios_base::floatfield);
	cout.precision(3);


	if(m > c)
	{
		cout << 0.000 << endl;
		continue;
	}


	for(i = 0;i <= c;i++)
	{
		backup[i] = 1.0;
		array[i][0] = 0.0;
		array[i][1] = 0.0;
	}

	array[1][0] = 1.0;
	n--;

	solve();


	cout.setf(ios_base::fixed, ios_base::floatfield);
	cout.precision(3);

//	cout << "N=" << n << endl;


	cout << array[m][(n+1)%2] << endl;

	}







}




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