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:Who solved it in mathematical way?In Reply To:Who solved it in mathematical way? Posted by:sehdan at 2008-12-04 19:36:50 > At first I wanna try to solved it in mathematical way, > Just as we all know,for the harmonic progression,while it achieve N,its sum is: > ∑1/i = ln N + γ,where γ equals to lim(∑1/i - ln N)≈0.577215... > so we can try to solve the following equation: > ln N >= c-γ+1 > then output N-1; > as the upper-limit just achieve 5.20,the accuracy of operation ought to be still enough.and I got all the correct answer for the test input. > but I got WA while sumbit it. I just wanna know the reason. > who can offer me an exactly explanation? > thanks. > and here is my code: > > #include <iostream> > #include <cstdio> > #include <cmath> > using namespace std; > > #define gama 0.577215 > #define e 2.718281 > > int main() > { > double c,n; > while(scanf("%lf",&c) != EOF && c != 0) > { > n = pow(e,c+1-gama); > printf("%.0lf card(s)\n",--n); > } > return 0; > } > > What's more...finally I AC it still in the "stupid" way that try N one by one... I think using the `stupid' solution can be accepted is because of the precision lost of floats. The answers were calculated in this stupid way. But mathematical way won't cause precision lost. So their answers are different. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator