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 |
这样肯定要超时,有没有好方法呢??求助#include <iostream.h> inline double dabs(double t) { if(t>=0) return t; else return -t; } void main() { double A; double d,n; int N,D; double exa; long L; cin >> A; int Ai = (int)A; cin >> L; exa = A - Ai; for( d=1;d <= L;d++) for(n=Ai * d ; n <= L;n++) if(dabs(n/d - A)<exa) {N = n; D = d; exa = dabs(n/d - A);} cout << N << ' ' << D <<endl; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator