这个代码,就是csp-j2012年的题目,有个问题,在注释里(注释开头标注了“我:”):
1 #include <iostream>
2
3 using namespace std;
4
5 int n,k;
6
7 int solve1()
8 {
9 int l = 0, r = n;
10 while(l <= r){
11 int mid = (l + r) / 2;
12 if (mid * mid <= n) l = mid + 1;
13 else r = mid - 1;
14 }
15 return l - 1;
16 }
17
18 double solve2(double x)
19 {
20 if (x == 0) return x;
21 for (int i = 0; i < k; i++)
22 x = (x + n / x) / 2;
23 return x;
24 }
25
26 int main()
27 {
28 cin >> n >> k;
29 double ans = solve2(solve1());
//我:我知道solve2()和solve2()是求ans的最大平方根 ,但 为什么
//solve2(solve1())也求得ans的最大平方根?还是说是我看的解析错了?
30 cout << ans << ' ' << (ans * ans == n) << endl;
31 return 0;
32 }