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 wanpi0user at 2005-05-16 22:48:03 on Problem 1650
请指点!
已通过测试数据。本程序未对分子分母化简,因为这没必要!
//******************************************************************
//*********                                                *********
//*********                                                *********
//wanpi0user
//
//******************************************************************
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<fstream>
#include<sstream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<string>
using namespace std;
int main(){
	int d,L,p,i;
	double eps=1.0;
	double A,D,P;
	cin>>A>>L;
	for(i=1;i<L;i++){
		D=i;
		P=floor(D*A+0.5);
		//if((P<L)&&(abs(P/D-A)<eps)){eps=abs(P/D-A);d=i;p=floor(D*A+0.5);}
		if(P<L&&(fabs(P/D-A)<eps)){
			eps=fabs(P/D-A);
			d=i;p=floor(D*A+0.5);}
		//cout<<(P/D-A)<<'\t'<<setw(10)<<eps<<'\t'<<A<<endl;
	}
	cout<<p<<" "<<d<<endl;
	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