Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:你自己试一下一些极端的数据吧,例如边界值什么的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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator