其他分享
首页 > 其他分享> > CodeForces - 851C-Five Dimensional Points(平面几何+数学)

CodeForces - 851C-Five Dimensional Points(平面几何+数学)

作者:互联网

题目:CodeForces - 851C

题意:一个5维坐标图中能够找到点a,点a满足与任意两个点b,c所成直线的夹角不为锐角

题解:直接暴力枚举点,然后用arccos公式求得两直线所成夹角度数,具体方法可以去传送门看一下

代码:

//Ö±½Ó±©Á¦£¬×¢Ò⻡¶Èת½Ç¶È 
#include<bits/stdc++.h>
#define N 1005
//#define PI 3.1415926
using namespace std;
const double PI=acos(-1.0);
int k=0,n;
int ans[1010];
double a[N],b[N],c[N],d[N],e[N];
bool flag;
double make(int i,int j,int k)
{
	double num=(a[j]-a[i])*(a[k]-a[i])+(b[j]-b[i])*(b[k]-b[i])+(c[j]-c[i])*(c[k]-c[i])+(d[j]-d[i])*(d[k]-d[i])+(e[j]-e[i])*(e[k]-e[i]);
	return num;
}
double take(int i,int j,int k)
{
	double x=(a[j]-a[i])*(a[j]-a[i])+(b[j]-b[i])*(b[j]-b[i])+(c[j]-c[i])*(c[j]-c[i])+(d[j]-d[i])*(d[j]-d[i])+(e[j]-e[i])*(e[j]-e[i]);
	double y=(a[k]-a[i])*(a[k]-a[i])+(b[k]-b[i])*(b[k]-b[i])+(c[k]-c[i])*(c[k]-c[i])+(d[k]-d[i])*(d[k]-d[i])+(e[k]-e[i])*(e[k]-e[i]);
	double num=sqrt(x*y);
	return num;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lf%lf%lf%lf%lf",&a[i],&b[i],&c[i],&d[i],&e[i]);
	for(int i=1;i<=n;i++)
	{
		flag=0;
		for(int j=1;j<=n;j++)
		{
			if(i==j)continue;
			for(int k=j+1;k<=n;k++)
			{
				if(k==i)continue;
				double x=make(i,j,k);
				double y=take(i,j,k);
				double z=acos(x/y)*180.0/PI;//要乘以(180.0/PI)才能转化为角度
				if(z<90.0){flag=1;break;}
			}
			if(flag)break;
		}
		if(!flag)
		{
			k++;
			ans[k]=i;
		}
	}
	printf("%d\n",k);
	for(int i=1;i<=k;i++)printf("%d ",ans[i]);
	return 0;
}

 

标签:平面几何,return,int,double,CodeForces,Dimensional,num,PI
来源: https://blog.csdn.net/Ljh_handsome/article/details/100019069