답안 #5177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
5177 2014-02-13T23:31:08 Z cki86201 초록색 삼각형 (YDX13_green) C++
1 / 1
424 ms 1464 KB
#include<stdio.h>
#include<algorithm>
#include<math.h>

typedef long long ll;

const double PI = 3.141592653589793238;

int x[2020], y[2020], ord[2020];
double an[2020];
int n;

bool comp(const int &a,const int &b){return an[a] < an[b];}

inline ll ccw(int a,int b,int c)
{
	return (ll)(x[b]-x[a]) * (y[c]-y[a]) - (ll)(x[c]-x[a]) * (y[b]-y[a]);
}

double brute(int u)
{
	int i, j, k;
	double ret = 0;
	for(i=3;i<=u;i++){
		for(j=2;j<i;j++){
			for(k=1;k<j;k++){
				ll tmp = (ll)(x[j]-x[i])*(y[k]-y[i])-(ll)(x[k]-x[i])*(y[j]-y[i]);
				if(tmp < 0)tmp = -tmp;
				ret += tmp;
			}
		}
	}
	return ret;
}

double chk[2020];

double solve(int u)
{
	if(u <= 10)return brute(u);
	double ret = 0;
	int i;
	for(i=1;i<=u;i++)ord[i] = i;
	for(i=1;i<=u;i++)an[i] = atan2(y[i] - y[u], x[i] - x[u]);
	std::sort(ord+1,ord+1+u,comp);
	int t = (ord[1] == u)?2:1;
	ll now[2] = {0,0};
	for(i=1;i<=u;i++){
		int ni = ord[i];
		if(ni == u)continue;
		now[0] -= x[ni] - x[u], now[1] -= y[ni] - y[u];
		while(ord[t] == u || t == i)now[0] += x[ord[t]] - x[u], now[1] += y[ord[t]] - y[u], t = t%u + 1;
		while(t!=i && ccw(u,ni,ord[t]) > 0){
			now[0] += x[ord[t]] - x[u];
			now[1] += y[ord[t]] - y[u];
			t = t%u + 1;
			if(ord[t] == u)t = t%u + 1;
		}
		ret += (double)now[1] * (x[ni] - x[u]) - (double)now[0] * (y[ni] - y[u]);
	}
	return ret + solve(u-1);
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",x+i,y+i);
	if(n<=2)return printf("0")&0;
	printf("%.12f\n",solve(n)*3/n/(n-1)/(n-2));
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1368 KB Output is correct
2 Correct 0 ms 1368 KB Output is correct
3 Correct 0 ms 1368 KB Output is correct
4 Correct 0 ms 1368 KB Output is correct
5 Correct 0 ms 1368 KB Output is correct
6 Correct 0 ms 1368 KB Output is correct
7 Correct 0 ms 1368 KB Output is correct
8 Correct 0 ms 1368 KB Output is correct
9 Correct 0 ms 1368 KB Output is correct
10 Correct 0 ms 1368 KB Output is correct
11 Correct 76 ms 1368 KB Output is correct
12 Correct 148 ms 1376 KB Output is correct
13 Correct 92 ms 1368 KB Output is correct
14 Correct 384 ms 1448 KB Output is correct
15 Correct 32 ms 1368 KB Output is correct
16 Correct 368 ms 1444 KB Output is correct
17 Correct 20 ms 1368 KB Output is correct
18 Correct 56 ms 1368 KB Output is correct
19 Correct 96 ms 1368 KB Output is correct
20 Correct 0 ms 1368 KB Output is correct
21 Correct 420 ms 1460 KB Output is correct
22 Correct 420 ms 1460 KB Output is correct
23 Correct 416 ms 1456 KB Output is correct
24 Correct 412 ms 1460 KB Output is correct
25 Correct 420 ms 1460 KB Output is correct
26 Correct 424 ms 1460 KB Output is correct
27 Correct 416 ms 1460 KB Output is correct
28 Correct 416 ms 1456 KB Output is correct
29 Correct 412 ms 1464 KB Output is correct
30 Correct 420 ms 1464 KB Output is correct
31 Correct 0 ms 1368 KB Output is correct