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;
}
#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;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

I Tried Viral Kitchen Gadgets For 30 Days Here Is the Honest Truth

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

ROSIE SERENADES THE DON…

Comedian and television personality Rosie O’Donnell wrapped up her week-long stint as guest host on Jimmy Kimmel Live! with an unforgettable, razor-sharp send-off aimed...

Everything You Need to Know About Viral Kitchen Gadgets Right Now

📢 As an Amazon Associate, I earn from qualifying purchases.Most products in this category disappoint within weeks. Cheap materials, vague instructions, and results that...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!