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

测试其他数据都对 就0.04错 谁能帮忙看下

Posted by y17498384 at 2013-05-09 23:43:32 on Problem 1003
#include <iostream>
using namespace std;
const double delta=1e-8;		//精度范围

int zero(double x)
{
	if(x>delta)
		return 1;
	if(x<-delta)
		return -1;
	else return 0;
}

int main()
{
	int total,i;
	double len[1000]={0};
	for(total=1;zero(len[total-1]-5.20)<0;total++)		//建一离线表,len[i]表示前i张卡片一共伸出的长度和
		len[total]=len[total-1]+(double)(1.0/(total+1));
	int left,right,mid;
	double x;
	cin>>x;
	while(zero(x))		//用二分法在离线表中检索
	{
		left=1;
		right=total;
		while(left+1<right)
		{
			mid=(left+right)/2;
			if(zero(len[mid]-x)<0)
			{
				left=mid;
			}
			else
			{
				right=mid;
			}
		}
		cout<<right<<" card(s)"<<endl;
		cin>>x;
	}
	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