답안 #5182

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
5182 2014-02-13T23:46:16 Z cki86201 초록색 삼각형 (YDX13_green) C++
0 / 1
0 ms 1352 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 solve(int u)
{
	if(u == 3){
		double tmp = (double)(x[2]-x[1])*(y[3]-y[1]) - (double)(x[3]-x[1])*(y[2]-y[1]);
		return tmp>0?tmp/2:-tmp/2;
	}
	if(u <= 2)return 0;
	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 Incorrect 0 ms 1352 KB Output isn't correct
2 Halted 0 ms 0 KB -