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 ssssss at 2009-05-12 11:16:07 on Problem 2537
/*
PKU 2537
Author : Yizer
*/
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

long double pow(int base,int pwr)
{
	long double ret = 1.0;
	for (int i=0;i<pwr;i++)
		ret *= base;
	return	ret;
}

int main()
{
	#ifndef ONLINE_JUDGE
//	freopen("data.in","r",stdin);
//	freopen("data.out","w",stdout);
	#endif
	int n , k;
	long double d[101][10];
	for (int i=0;i<10;i++)
		d[0][i] = 1;
	while (scanf("%d%d",&k,&n)!=EOF)
	{
		if(!k)
		{
			//cout<<"100.00000\n";
			//puts("100.00000");
printf("%.5lf\n",100.0);
			continue;
		}
		for (int i=1;i<n;i++)
		{
			d[i][0] = d[i-1][1] + d[i-1][0];
			for (int j=1;j<k;j++)
				d[i][j] = d[i-1][j-1] + d[i-1][j+1] + d[i-1][j];
			d[i][k] = d[i-1][k-1] + d[i-1][k];
		}
		long double sum = 0;
		for (int i=0;i<=k;i++)
			sum += d[n-1][i];
		sum *= 100;
		printf("%.5Lf\n",sum/pow(k+1,n));
	}
	return	0;
} 

/*
PKU 2537
Author : Yizer
*/
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

long double pow(int base,int pwr)
{
	long double ret = 1.0;
	for (int i=0;i<pwr;i++)
		ret *= base;
	return	ret;
}

int main()
{
	#ifndef ONLINE_JUDGE
//	freopen("data.in","r",stdin);
//	freopen("data.out","w",stdout);
	#endif
	int n , k;
	long double d[101][10];
	for (int i=0;i<10;i++)
		d[0][i] = 1;
	while (scanf("%d%d",&k,&n)!=EOF)
	{
		if(!k)
		{
			//cout<<"100.00000\n";
			puts("100.00000");
			continue;
		}
		for (int i=1;i<n;i++)
		{
			d[i][0] = d[i-1][1] + d[i-1][0];
			for (int j=1;j<k;j++)
				d[i][j] = d[i-1][j-1] + d[i-1][j+1] + d[i-1][j];
			d[i][k] = d[i-1][k-1] + d[i-1][k];
		}
		long double sum = 0;
		for (int i=0;i<=k;i++)
			sum += d[n-1][i];
		sum *= 100;
		printf("%.5Lf\n",sum/pow(k+1,n));
	}
	return	0;
} 

代码区别在于
puts("100.00000");
printf("%.5lf\n",100.000000);
G++WA
C++AC
如果这是精度问题的话。。这精度差的也太大了吧
100.000000都有精度问题
我调了一上午

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