9-7 (空间推想,思路,图论水)
来源:互联网 发布:通利琴行淘宝店铺 编辑:程序博客网 时间:2024/05/17 18:47
Five Dimensional Points
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
input
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
output
1
1
input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
output
0
Note
In the first sample, the first point forms exactly a angle with all other pairs of points, so it is good.
可以从二维的开始推,发现五维有好点的极限情况是10个坐标轴上的点加一个原点,否则无好点
自己这个代码,是发现最多只有一个好点之后很直接的暴力……
#include <bits/stdc++.h>using namespace std;const int maxn = 1010;struct Point{ int a,b,c,d,e; int flag;}p[maxn];int n;bool check(Point& a, Point& b, Point& c){ //写代码要细心呀,这部分最开始打错一个字母…… int a1 = c.a - a.a, a2 = c.a - b.a; int b1 = c.b - a.b, b2 = c.b - b.b; int c1 = c.c - a.c, c2 = c.c - b.c; int d1 = c.d - a.d, d2 = c.d - b.d; int e1 = c.e - a.e, e2 = c.e - b.e; if(a1*a2 + b1*b2 + c1*c2 + d2*d1 + e1*e2 > 0) return true; else return false;}void judge(int a, int b){ for(int i = 0; i < n; i++){ if(p[i].flag || i == a || i == b) continue; if(check(p[a], p[b], p[i])) p[i].flag = 1; if(!p[a].flag && check(p[b], p[i], p[a])) p[a].flag = 1; if(!p[b].flag && check(p[a], p[i], p[b])) p[b].flag = 1; }}int main(){ while(~scanf("%d", &n)){ for(int i = 0; i < n; i++){ scanf("%d%d%d%d%d", &p[i].a, &p[i].b, &p[i].c, &p[i].d, &p[i].e); p[i].flag = 0; } int a[2]; int cnt = 0; for(int i = 0; i < n; i++){ if(p[i].flag) continue; a[cnt++] = i; if(cnt == 2){ judge(a[0], a[1]); cnt = 0; } } cnt = 0; for(int i = 0; i < n; i++){ if(!p[i].flag) { for(int j = 0; j < n; j++){ for(int k = j+1; k < n; k++) if(j!=i && k!=i && check(p[j], p[k], p[i])) {p[i].flag = 1;break;} if(p[i].flag) break; } if(!p[i].flag) cnt++; } } printf("%d\n", cnt); for(int i = 0; i < n; i++) if(!p[i].flag) printf("%d\n", i+1); } return 0;}
Arpa and an exam about geometry
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It’s guaranteed that the points are distinct.
Output
Print “Yes” if the problem has a solution, “No” otherwise.
You can print each letter in any case (upper or lower).
Examples
input
0 1 1 1 1 0
output
Yes
input
1 1 0 0 1000 1000
output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by .
In the second sample test, you can’t find any solution.
如果ab,bc长度相同即可,注意排除共线的情况(血的教训)
#include <bits/stdc++.h>using namespace std;double dist(double x1, double y1, double x2, double y2){ double dx = x1 - x2; double dy = y1 - y2; return dx*dx + dy*dy;}int main(){ double x1, x2, x3, y1, y2, y3; while( cin>>x1>>y1>>x2>>y2>>x3>>y3){ if((y2-y1)*(x3-x1) == (x2-x1)*(y3-y1)){ printf("No\n"); continue; } double d1 = dist(x1, y1, x2, y2); double d2 = dist(x2, y2, x3, y3); if(d1 == d2) printf("Yes\n"); else printf("No\n"); } return 0;}
吝啬的国度
描述
在一个吝啬的国度里有N个城市,这N个城市间只有N-1条路把这个N个城市连接起来。现在,Tom在第S号城市,他有张该国地图,他想知道如果自己要去参观第T号城市,必须经过的前一个城市是几号城市(假设你不走重复的路)。
输入
第一行输入一个整数M表示测试数据共有M(1<=M<=5)组
每组测试数据的第一行输入一个正整数N(1<=N<=100000)和一个正整数S(1<=S<=100000),N表示城市的总个数,S表示参观者所在城市的编号
随后的N-1行,每行有两个正整数a,b(1<=a,b<=N),表示第a号城市和第b号城市之间有一条路连通。
输出
每组测试数据输N个正整数,其中,第i个数表示从S走到i号城市,必须要经过的上一个城市的编号。(其中i=S时,请输出-1)
无根树转换为有根树,注意dfs时利用的树的性质,水
#include <bits/stdc++.h>using namespace std;const int maxn = 100010;vector<int> vec[maxn];int s, n;int fa[maxn];void dfs(int u, int f){ for(int i = 0; i < vec[u].size(); i++) if(vec[u][i] != f){ fa[vec[u][i]] = u; dfs(vec[u][i], u); }}int main(){ int t; scanf("%d", &t); while(t--){ scanf("%d%d", &n, &s); for(int i = 1; i <= n; i++) vec[i].clear(); for(int i = 1; i < n; i++){ int a, b; scanf("%d%d", &a, &b); vec[a].push_back(b); vec[b].push_back(a); } memset(fa, 0, sizeof(fa)); fa[s] = -1; dfs(s, -1); for(int i = 1; i <= n; i++){ if(i != 1) printf(" "); printf("%d", fa[i]); } printf("\n"); } return 0;}
- 9-7 (空间推想,思路,图论水)
- 推想
- 空间转换思路
- 透视网络空间思路
- 空间索引思路整理
- 两栈共享空间思路
- 整理下思路(7)
- 为QQ空间推广整理思路
- QQ空间权限限制破解思路
- 时间复杂度和空间复杂度估算思路
- 鼠标滚轮到最底端继续加载新数据思路(多用于微博、空间、论坛)
- 鼠标滚轮到最底端继续加载新数据思路(多用于微博、空间、论坛)
- 9/7 正则表达式思路总结
- 9-27 (最短路,两端思路)
- iPhone使用外接镜头不再繁琐,推一推想用就用
- JSP空间网站上传后发生404解决思路
- 某个表空间的数据文件损坏的修复思路
- hduDP题(思路)
- Codeforces Round #432 Div. 1 C. Arpa and a game with Mojtaba
- C51单片机硬件基础
- 剑指offer--替换空格(java)
- Java中的泛型
- Oracle SQL命令
- 9-7 (空间推想,思路,图论水)
- Unity3D-塔防游戏项目主要源码(游戏主控器脚本)
- 对一阶二阶低通数字滤波器的理解(基于匿名微型六轴)
- GDI+的使用
- 样本方差的无偏估计与(n-1)的由来
- 聊聊流水线处理器
- 51nod 1753 相似子串
- Unity3D-塔防游戏项目主要源码(游戏UI界面控制器脚本)
- FSM