zoj 1337 Pi
来源:互联网 发布:js获取div的属性值 编辑:程序博客网 时间:2024/04/20 09:50
#include "iostream"#include "memory.h"#include "math.h"#include "stdio.h"using namespace std;int input[60];int main(){ memset(input, 0, sizeof(input)); int num, i, j, count, sumcount, g, x, y; double pi, ans; while (cin >> num && num) { count = ans = pi = g = 0; sumcount = num * (num - 1) / 2; for (i = 1; i <= num; i++) cin >> input[i]; for (i = 1; i < num; i++) for (j = i + 1; j <= num; j++) { x = input[i], y = input[j]; while (y && x) { y = y % x; if (y) x = x % y; } g = (y != 0) ? y : x; if (g == 1) count++; } if (count == 0) cout << "No estimate for this data set." << endl; else { ans = 6.0 * sumcount / count;//一直都WA,原来问题出现在这里,应该是6.0,而不是6,所以精度降低了!粗心! //pi = pow(ans , 1.0/2); pi = sqrt(ans); printf("%.6lf\n", pi); } } }