Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2), problem: (D) Volatile Kite Solution In C/C++

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 1005
int x[maxn],y[maxn];
int n;

long long area(int i)
{
	int j=(i-1+n)%n,k=(i+1)%n;
	long long x1=x[i]-x[j],y1=y[i]-y[j],
		x2=x[i]-x[k],y2=y[i]-y[k];
	return abs(x1*y2-x2*y1);
}

double length(int i)
{
	int j=(i-1+n)%n,k=(i+1)%n;
	long long dx=x[j]-x[k],dy=y[j]-y[k];
	return sqrt(dx*dx+dy*dy);
}

int main()
{
	int i,j,k;
	double ans;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d%d",x+i,y+i);

	ans=4e9;
	for(i=0;i<n;i++)
		ans=min(ans,area(i)/length(i)/2.0);
	printf("%.10lf",ans);
	return 0;
}
(Visited 9 times, 1 visits today)

About the Author:

Leave A Comment