Codeforces Round #432 Div. 2 C. Five Dimensional Points(数学)

来源:互联网 发布:淘宝运营月计划书 编辑:程序博客网 时间:2024/05/29 19:44

C. Five Dimensional Points
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.

We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors这里写图片描述 and这里写图片描述 is acute (i.e. strictly less than这里写图片描述 ). Otherwise, the point is called good.
The angle between vectors 这里写图片描述 and 这里写图片描述 in 5-dimensional space is defined as这里写图片描述 , where 这里写图片描述 is the scalar product and这里写图片描述 is length of 这里写图片描述 .
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.

The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.

Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
这里写图片描述
Note
In the first sample, the first point forms exactly a 这里写图片描述 angle with all other pairs of points, so it is good.

In the second sample, along the cd plane, we can see the points look as follows:
这里写图片描述


题意是:求在5维空间中给出的n个点中有多少个“好点”。
其中好点的定义为:一个点与其他点所组成的向量的夹角大于等于90度。
否则为坏点。
思路:数学很重要,在二维空间中相互垂直的有两个向量,在三维空间中则有三个向量相互垂直。所以在五维空间中,则有五个向量相互垂直。利用则在该空间中若存在相互两两垂直的向量,最多有11个点(五个向量相交的点+五个向量所组成的点=1+2*5),否则肯定不存在好点。若小于三个点,则一定为好点。

#include<stdio.h>#include<iostream>#include<cmath>#include<algorithm>#include<cctype>#include<string.h>#include<queue>#include<stdlib.h>using namespace std;int m[1050][10];bool mark[1050];//mark用来标记那个点为好点,好点为true,坏点为false。int main(){    int n;    scanf("%d",&n);    for(int i=1;i<=n;i++)    {        for(int j=1;j<=5;j++)        {            scanf("%d",&m[i][j]);        }    }    if(n<3)//小于3的情况    {        printf("%d\n",n);        for(int i=1;i<=n;i++)        {            printf("%d\n",i);        }    }    else if(n>11)//大于11的情况    {        printf("0\n");    }    else     {        int x,y,xy,sum=0;        memset(mark,0,sizeof(mark));//开始把所以点都初始化为坏点        for(int i=1;i<=n;i++)//从第一个点开始枚举        {            int flag=0;//用来看是否为坏点的标记            for(int j=1;j<=n&&flag==0;j++)//j,k中枚举与i点所组成向量            {                if(i==j)continue;                for(int k=1;k<=n&&flag==0;k++)                {                    if(i==k||j==k)continue;                    x=0,y=0,xy=0;                    for(int z=1;z<=5;z++)                    {                        x+=(m[j][z]-m[i][z])*(m[j][z]-m[i][z]);//向量x的模的平方                        y+=(m[k][z]-m[i][z])*(m[k][z]-m[i][z]);//向量y的模的平方                        xy+=(m[j][z]-m[i][z])*(m[k][z]-m[i][z]);//向量xy的点积                       }                    double s=sqrt(x)*sqrt(y);//向量x与向量y模的乘积                    if(acos(xy/s)>=0&&acos(xy/s)<3.1415926/2.0)//小于90度判定的条件                    {                        flag=1;//若为坏点则直接跳出                        break;                     }                }                if(flag)                break;            }            if(!flag)            {                mark[i]=1;                sum++;            }        }        printf("%d\n",sum);        for(int i=1;i<=n;i++)        {            if(mark[i])            printf("%d\n",i);        }    }    return 0;} 
阅读全文
0 0
原创粉丝点击