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:为啥我这样做5.19求出272张卡In Reply To:为啥我这样做5.19求出272张卡 Posted by:ranzhouhua at 2019-07-18 17:11:24 > #include<iostream> > using namespace std; > > int hangover( double x) > { > int n=1; > double cardlength,a,b; > cardlength = 1.0 / (n + 1); > for (cardlength;cardlength<x;cardlength += 1.0 / (n + 1)) > { > n++; > } > a = cardlength-1.0/(n+1); > b = cardlength; > if ((x - a) > (b - x)) > { > return n; > } > else > return n-1; > } > > int main() > { > double x; > while (cin >> x&&x!=0.00) > { > int n=hangover(x); > cout << n << " card(s)" << endl; > } > return 0; > } 不需要 if ((x - a) > (b - x)) 的判断 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator