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

Re:你自己试一下一些极端的数据吧,例如边界值什么的

Posted by wanpi0user at 2005-05-23 18:08:23 on Problem 1650
In Reply To:你自己试一下一些极端的数据吧,例如边界值什么的 Posted by:frkstyc at 2005-05-23 17:53:40
我试了。您看我的程序:
//******************************************************************
//*********                                                *********
//*********                                                *********
//wangping 
//
//******************************************************************
#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;
	if(fabs(A-1.0)<1e-12){cout<<"1 1\n";return 0;}
	if(fabs(A-2.0)<1e-12){cout<<"2 1\n";return 0;}
	if(fabs(A-3.0)<1e-12){cout<<"3 1\n";return 0;}
	if(fabs(A-4.0)<1e-12){cout<<"4 1\n";return 0;}
	if(fabs(A-5.0)<1e-12){cout<<"5 1\n";return 0;}
	if(fabs(A-6.0)<1e-12){cout<<"6 1\n";return 0;}
	if(fabs(A-7.0)<1e-12){cout<<"7 1\n";return 0;}
	if(fabs(A-8.0)<1e-12){cout<<"8 1\n";return 0;}
	if(fabs(A-9.0)<1e-12){cout<<"9 1\n";return 0;}
	if(fabs(A-10.0)<1e-12){cout<<"10 1\n";return 0;}
	if(fabs(A)<1e-12){cout<<"0 1\n";return 0;}
	for(i=1;i<=L;i++){
		D=i;
		P=floor(D*A+0.5);if(P<=L){
		//if((P<L)&&(abs(P/D-A)<eps)){eps=abs(P/D-A);d=i;p=floor(D*A+0.5);}
		if((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