Five Dimensional Points CodeForces - 851C (计算几何+暴力)
2 seconds
256 megabytes
standard input
standard 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.
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.
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.
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
1
1
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
0
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:

We can see that all angles here are acute, so no points are good.
题意:
给你n个五维空间上的n个点。
让你求出“好”的点的数量。
“好”的点的定义是:
对于一个点i,不存在任何其他两个点,j,k, (三个点互不相同) 使得向量 i->j和向量 i - > k 是锐角。
思路:
判断两个向量的夹角是否是锐角可以通过向量的点积来判断。
五维空间的点积和二维三维的都一样,都是对应坐标相乘再相加。
然后每一次点积后的结果都可以得出这样的结论。

如图,如果点积后的结果小于等于零,那么证明∠J I K不是锐角。
那么就得出结论 j 和k都不是good点,因为对于j,有i和k是的所成的角是锐角。
k同理。
而如果点积结果大于0,那么证明 角jik是锐角,所以i不是good point
需要一个数组vis来维护哪些点是已经被确定不是good点的,以此来降低时间复杂度。
注意到枚举的时候,第三个变量k,设为j+1开始枚举,这样不会让i,j,k每一次重复计算而导致答案错误。
细节见代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int vis[maxn];
struct node
{
ll a,b,c,d,e;
}arr[maxn];
int n;
ll f(int i,int j,int k)
{
ll a1=arr[j].a-arr[i].a;
ll a2=arr[k].a-arr[i].a;
ll b1=arr[j].b-arr[i].b;
ll b2=arr[k].b-arr[i].b;
ll c1=arr[j].c-arr[i].c;
ll c2=arr[k].c-arr[i].c;
ll d1=arr[j].d-arr[i].d;
ll d2=arr[k].d-arr[i].d;
ll e1=arr[j].e-arr[i].e;
ll e2=arr[k].e-arr[i].e;
ll res=a1*a2+b1*b2+c1*c2+d1*d2+e1*e2;
return res;
}
int main()
{
//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout); gbtb;
cin>>n;
repd(i,,n)
{
cin>>arr[i].a>>arr[i].b>>arr[i].c>>arr[i].d>>arr[i].e;
}
repd(i,,n)
{
if(i==)
{
i=;
}
if(vis[i])
continue;
repd(j,,n)
{
if(i==j)
{
continue;
}
repd(k,j+,n)
{
if(k==j||k==i)
{
continue;
}
if(f(i,j,k)<=)
{
vis[j]=vis[k]=;
break;
}else
{
vis[i]=;
break;
}
}
if(vis[i])
break;
}
}
int ans=;
repd(i,,n)
{
if(!vis[i])
{
ans++;
}
}
cout<<ans<<endl;
repd(i,,n)
{
if(!vis[i])
{
cout<<i<<" ";
}
}cout<<endl;
return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}
Five Dimensional Points CodeForces - 851C (计算几何+暴力)的更多相关文章
- codeforces 851C Five Dimensional Points(鸽巢原理)
http://codeforces.com/contest/851/problem/C 题意 - 给出 n 个五维空间的点 - 一个点a为 bad 的定义为 存在两点 b, c, 使的<ab, ...
- Codeforces 850A - Five Dimensional Points(暴力)
原题链接:http://codeforces.com/problemset/problem/850/A 题意:有n个五维空间内的点,如果其中三个点A,B,C,向量AB,AC的夹角不大于90°,则点A是 ...
- 【推导】【暴力】Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) C. Five Dimensional Points
题意:给你五维空间内n个点,问你有多少个点不是坏点. 坏点定义:如果对于某个点A,存在点B,C,使得角BAC为锐角,那么A是坏点. 结论:如果n维空间内已经存在2*n+1个点,那么再往里面添加任意多个 ...
- 【Codeforces Round #432 (Div. 1) A】 Five Dimensional Points
[链接]点击打开链接 [题意] 给你n个5维的点. 然后让你以其中的某一个点作为起点a. 另选两个点b,c. 组成向量a->b,a->c 如果所有的a->b和a->c的夹角都是 ...
- HDU 6697 Closest Pair of Segments (计算几何 暴力)
2019 杭电多校 10 1007 题目链接:HDU 6697 比赛链接:2019 Multi-University Training Contest 10 Problem Description T ...
- Chladni Figure CodeForces - 1162D (暴力,真香啊~)
Chladni Figure CodeForces - 1162D Inaka has a disc, the circumference of which is nn units. The circ ...
- Karen and Game CodeForces - 816C (暴力+构造)
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as fo ...
- zoj 1081:Points Within(计算几何,判断点是否在多边形内,经典题)
Points Within Time Limit: 2 Seconds Memory Limit: 65536 KB Statement of the Problem Several dra ...
- BZOJ 1199: [HNOI2005]汤姆的游戏 计算几何暴力
1199: [HNOI2005]汤姆的游戏 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...
随机推荐
- 洗礼灵魂,修炼python(64)--爬虫篇—re模块/正则表达式(2)
前面学习了元家军以及其他的字符匹配方法,那得会用啊对吧?本篇博文就简单的解析怎么运用 正则表达式使用 前面说了正则表达式的知识点,本篇博文就是针对常用的正则表达式进行举例解析.相信你知道要用正则表达式 ...
- Latch导致MySQL Crash
作者:沃趣科技数据库专家 董红禹 问题概述 最近我们遇到一个MySQL的问题,分析后很有代表意义,特地写出来供大家参考.出现问题是,数据库先是被置为只读,然后过了一段时间,MySQL直接Crash掉了 ...
- Linux CFS调度器之虚拟时钟vruntime与调度延迟--Linux进程的管理与调度(二十六)
1 虚拟运行时间(今日内容提醒) 1.1 虚拟运行时间的引入 CFS为了实现公平,必须惩罚当前正在运行的进程,以使那些正在等待的进程下次被调度. 具体实现时,CFS通过每个进程的虚拟运行时间(vrun ...
- 排序算法之冒泡排序的思想以及Java实现
1 基本思想 设排序表长为n,从后向前或者从前向后两两比较相邻元素的值,如果两者的相对次序不对(A[i-1] > A[i]),则交换它们,其结果是将最小的元素交换到待排序序列的第一个位置,我们称 ...
- Sublime 汉化、快捷键打开浏览器
Sublime 是一个优秀的代码编译工具,它具有漂亮的用户界面和强大的功能,例如代码缩略图,Python 的插件,代码段等.不仅如此,它还可自定义按键绑定,菜单和工具栏.由于是歪果仁开发的,所以官方版 ...
- 小程序View内的文字不换行
今天发现View内的文字一行过去直接被屏幕右边吃掉,没有预期的换行,设置width也不管用,最后用它解决了 1. white-space:pre-line(不会保留空白和tabs) 2. white- ...
- C#反射の一个泛型反射实现的网络请求框架
点击下载源码 C#反射の反射详解(点击跳转)C#反射の反射接口(点击跳转)C#反射反射泛型接口(点击跳转)C#反射の一个泛型反射实现的网络请求框架(点击跳转)
- Python实现矿池
自建P2POOL矿池详细教程(高级篇)http://8btc.com/article-1804-1.html p2pool比特币矿池教程综合篇(包含linux矿池教程)https://www.cybt ...
- [matlab] 18.图与网络 (转载)
基本概念: 图论[Graph Theory]是数学的一个分支.它以图为研究对象.图论中的图是由若干给定的点及连接两点的线所构成的图形,这种图形通常用来描述某些事物之间的某种特定关系,用点代表事物,用连 ...
- Clickhouse副本表以及分布式表简单实践
集群配置: 192.168.0.106 node3 192.168.0.101 node2 192.168.0.103 node1 zookeeper配置忽略,自行实践! node1配置: <? ...