美丽角对

  • asin、acos、atan:反正弦、反余弦、反正切函数
  • 可以利用以上函数得到Π的值
  • 注意1的特判
点击查看代码
#include <bits/stdc++.h>
using namespace std;
struct t1
{
	long long x,y;
}t[100005];
long long read1()
{
	char cc=getchar();
	while(!(cc>=48&&cc<=57))
	{
		if(cc=='-')
		{
			break;
		}
		cc=getchar();
	}
	bool f=false;
	long long s=0;
	if(cc=='-')
	{
		f=true;
	}
	else
	{
		s=cc-48;
	}
	while(1)
	{
		cc=getchar();
		if(cc>=48&&cc<=57)
		{
			s=s*10+cc-48;
		}
		else
		{
			break;
		}
	}
	if(f==true)
	{
		s=-s;
	}
	return s;
}
t1 operator-(t1 a,t1 b)
{
	t1 tmp;
	tmp.x=a.x-b.x;
	tmp.y=a.y-b.y;
	return tmp;
}
long long c(t1 a,t1 b)
{
	return a.x*b.y-a.y*b.x;
}
double p(t1 a,t1 b)
{
	return a.x*b.x+a.y*b.y;
}
double l(t1 a)
{
	return sqrt(a.x*a.x+a.y*a.y);
}
bool cmp(t1 a,t1 b)
{
	t1 h1=a-t[1];
	t1 h2=b-t[1];
	if(c(h1,h2)!=0)
	{
		return c(h1,h2)>0;
	}
	return h1.x<h2.x;
}
long long gcd(long long n,long long m)
{
	if(m==0)
	{
		return n;
	}
	return gcd(m,n%m);
}
long long s[100005],tot,cnt[200];
int main()
{
	long long n;
	cin>>n;
	for(long long i=1;i<=n;i++)
	{
		t[i].x=read1();
		t[i].y=read1();
		if(t[i].y<t[1].y||t[i].y==t[1].y&&t[i].x<t[1].x)
		{
			swap(t[i],t[1]);
		}
	}
	sort(t+2,t+n+1,cmp);
	tot=1;
	s[1]=1;
	for(long long i=2;i<=n;i++)
	{
		while(tot>1)
		{
			t1 h1=t[i]-t[s[tot]];
			t1 h2=t[s[tot]]-t[s[tot-1]];
			if(c(h1,h2)>=0)
			{
				tot--;
			}
			else
			{
				break;
			}
		}
		tot++;
		s[tot]=i;
	}
	tot++;
	s[tot]=1;
	tot++;
	s[tot]=s[2];
	for(long long i=2;i<=tot-1;i++)
	{
		t1 h1=t[s[i-1]]-t[s[i]];
		t1 h2=t[s[i+1]]-t[s[i]];
		double d=acos(p(h1,h2)/l(h1)/l(h2));
		d=d/acos(-1)*180;
		int D=floor(d);
		cnt[D]++;
	}
	long long ans=cnt[1]*(cnt[1]-1)/2;
	for(long long i=0;i<180;i++)
	{
		for(long long j=i+1;j<180;j++)
		{
			if(gcd(i,j)==1)
			{
				ans=ans+cnt[i]*cnt[j];
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
posted @ 2024-01-29 15:23  D06  阅读(3)  评论(0编辑  收藏  举报