#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int N = 1225;
int t, n, tn;
struct Point {
double x, y;
void read() {
scanf("%lf%lf", &x, &y);
}
} p[N];
double r[2 * N];
double C(int n, int m) {
if (m > n) return 0;
double ans = 1;
for (int i = 0; i < m; i++)
ans = ans * (n - i) / (i + 1);
return ans;
}
double cal(Point a, Point b) {
return atan2(b.y - a.y, b.x - a.x);
}
double solve(int num) {
tn = 0;
double ans = 0;
for (int i = 0; i < n; i++) {
if (i == num) continue;
r[tn++] = cal(p[num], p[i]);
}
sort(r, r + tn);
int j = 1;
for (int i = 0; i < tn; i++)
r[i + tn] = r[i] + 2 * pi;
for (int i = 0; i < tn; i++) {
while (fabs(r[j] - r[i]) - pi < -eps) j++;
ans += C(j - i - 1, 2);
}
return C(tn, 3) - ans;
}
int main() {
int cas = 0;
while (scanf("%d", &n) && n) {
double ans = 0;
for (int i = 0; i < n; i++)
p[i].read();
for (int i = 0; i < n; i++) {
ans += solve(i);
}
printf("City %d: %.2lf\n", ++cas, ans / C(n, 3));
}
return 0;
}UVA 11529 - Strange Tax Calculation(计数问题),布布扣,bubuko.com
UVA 11529 - Strange Tax Calculation(计数问题)
原文:http://blog.csdn.net/accelerator_/article/details/26146071