思路:我们算每个点在多少个三角形内就行了.....我们枚举每个点为原点,然后统计有多少个三角形包含这个原点。统计的话,我们按照极角排序,当确定了两个点的时候,可以马上知道第三个点的区间,画个图就知道了.....当然直接这样枚举两个点的话单个点的复杂度就是n^2,这样显然不行嘛。。。其实这里我们可以降低一维的....用前缀和之类的搞搞它就行了。
代码:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <stdio.h>
#include <cmath>
#include <math.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,b,a) for(int i = (b); i >= (a); --i)
#define clr(a,x) memset(a,(x),sizeof(a))
#define LL long long
#define eps 1e-10
using namespace std;
const int maxn = 1200 + 5;
const double PI = 4.0 * atan(1.0);
int n;
struct Point
{
int x,y;
double ang;
Point(int x=0,int y=0)
:x(x),y(y) {
ang = atan2(y,x);
}
bool operator < (const Point & pt) const
{
return ang < pt.ang;
}
}pt[maxn],p[maxn];
void input()
{
rep(i,0,n) scanf("%d%d",&pt[i].x,&pt[i].y);
}
vector<int> v[4];
int sum[maxn];
LL inTriangle(int x,int y)
{
int c = 0;
rep(i,0,n) p[i] = pt[i];
rep(i,0,n) if (pt[i].x != x || pt[i].y != y) {
pt[c].x = p[i].x-x, pt[c].y = pt[i].y-y;
pt[c].ang = atan2(pt[c].y,pt[c].x);
++c;
}
sort(pt,pt+c);
int j = 1;
rep(i,0,c) {
if (j <= i) j = i + 1;
while (j < c && pt[j].ang <= pt[i].ang + PI) ++j; --j;
sum[i+1] = sum[i] + j - i;
// S[k] - (j-k+1)
}
LL ans = 0;
j = 1;
rep(i,0,c) {
if (j <= i) j = i + 1;
while (j < c && pt[j].ang <= pt[i].ang + PI) ++j; --j;
ans += sum[j+1] - sum[i] - ((j+1) * (j-i) - (i+1+j) * (j - i) / 2);
}
rep(i,0,n) pt[i] = p[i];
return ans;
}
void solve()
{
LL ans = 0;
rep(i,0,n) ans += inTriangle(pt[i].x,pt[i].y);
double fenmu = (LL) n * (n-1) * (n-2) / 6;
printf("%.2lf\n",(double)ans/fenmu);
}
int main()
{
#ifdef ACM
freopen("in.txt", "r", stdin);
// freopen("out.txt","w",stdout);
#endif // ACM
int cas = 0;
while (scanf("%d",&n),n) {
input();
++cas;
printf("City %d: ",cas);
solve();
}
}