B. Arpa and an exam about geometry

传送门:http://codeforces.com/contest/851/problem/B

本题是一个平面几何问题。

平面上有3个点A,B,C,坐标分别为(ax,ay),(bx,by),(cx,cy)。现以平面上一点P为中心,将点A,B,C旋转角度θ,旋转后的点分别为A’,B’,C’。试问:是否存在点P和角度θ,使得“点A’与点B重合,点B’与点C重合”?

以上条件等价于:存在点P和角度θ,使得“|PA|=|PB|=|PC|,且∠APB=BPC=θ”。

考虑点A,B,C的几何关系:

A,B,C位于同一条直线上,则不存在满足条件的点P和角度θ

A,B,C不位于同一条直线上,若存在满足条件的点P和角度θ,则由等价条件可知:△APB≌△BPC,因此|AB|=|BC|

因此,题中条件成立,当且仅当“A,B,C不共线,且|AB|=|BC|”。

A,B,C三点共线的一个充分条件是直线ABBC的斜率相等,但这是一个充分不必要条件。

A,B,C三点共线的一个充分必要条件可以通过向量形式给出:

向量α1=(Δx1y1)T,α2=(Δx2y2)T,其中Δx1=bx-axy1=by-ayx2=cx-bxy2=cy-by

若向量α1α2共线,则向量组α1,α2线性相关。设A=(α1,α2),则detA=0。

$$\det A=\left|\begin{matrix}\Delta x_1&\Delta x_2\\\Delta y_1&\Delta y_2\end{matrix}\right|=0\Leftrightarrow\Delta x_1\cdot\Delta y_2=\Delta x_2\cdot\Delta y_1$$

因此,A,B,C三点共线的一个充分必要条件是Δx1·Δy2x2·Δy1。参考程序如下:

#include <stdio.h>
#include <stdint.h> int main(void)
{
int ax, ay, bx, by, cx, cy;
scanf("%d%d%d%d%d%d", &ax, &ay, &bx, &by, &cx, &cy);
int64_t dx1 = bx - ax, dy1 = by - ay;
int64_t dx2 = cx - bx, dy2 = cy - by;
if (dx1 * dy2 == dx2 * dy1) printf("No\n");
else {
if (dx1 * dx1 + dy1 * dy1 == dx2 * dx2 + dy2 * dy2) printf("Yes\n");
else printf("No\n");
}
return ;
}

C. Five Dimensional Points

传送门:http://codeforces.com/contest/851/problem/C

本题是一个空间几何问题。

在五维空间中,有n个不同的点P1,P2,...,PnPi的坐标为(ai,bi,ci,di,ei)。现有定义:点A为bad,当且仅当存在不同于点A的点B和点C,使得向量ABAC的夹角为锐角;否则,点A为good。求{1,2,...,n}的子集S,使得对于S中的每一个元素i,均有Pi为good。

向量的夹角按照以下公式计算:$<\boldsymbol{a},\boldsymbol{b}>=\arccos \frac{\boldsymbol{a}\cdot \boldsymbol{b}}{|\boldsymbol{a}||\boldsymbol{b}|}$

而对于向量a=(a1,a2,...,ak),b=(b1,b2,...,bk),内积a·b的计算公式为: $\boldsymbol{a}\cdot\boldsymbol{b}=\sum_{j=1}^{k}{a_{j}b_{j}}$

本题直接模拟即可,时间复杂度为O(n3)。

参考程序如下:

#include <stdio.h>
#include <stdbool.h>
#define MAX_N 1000 typedef int quint[]; quint p[MAX_N], v[MAX_N][MAX_N];
int good[MAX_N]; int main(void)
{
int n;
scanf("%d", &n);
for (int i = ; i < n; i++) {
for (int k = ; k < ; k++) {
scanf("%d", &p[i][k]);
}
}
for (int i = ; i < n; i++) {
for (int j = ; j < n; j++) {
for (int k = ; k < ; k++) {
v[i][j][k] = p[j][k] - p[i][k];
}
}
}
int cnt = ;
for (int t = ; t < n; t++) {
bool flag = false;
for (int i = ; i < n; i++) {
for (int j = ; j < i; j++) {
int inp = ;
for (int k = ; k < ; k++) {
inp += v[t][i][k] * v[t][j][k];
}
if (inp > ) {
flag = true;
break;
}
}
}
if (!flag) {
good[cnt++] = t + ;
}
}
printf("%d\n", cnt);
for (int i = ; i < cnt; i++) {
printf("%d\n", good[i]);
}
return ;
}

Codeforces 851B/C的更多相关文章

  1. CodeForces - 851B -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,  ...

  2. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  3. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  4. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  5. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  6. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  7. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  8. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  9. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

随机推荐

  1. 【自己定义控件】android事件分发机制

    自己定义Viewgrou中我们或许会常常碰到这种情况,2个子控件的事件冲突导致滑动没实用了.滑动反应非常慢,点击没用了,要划非常多次才移动一点点等等.或许我们第一反应就是百度,google去搜索下答案 ...

  2. POJ2417 Baby-Step-Gaint-Step 算法

    考虑一个问题:A^x%p=B,给定A,B,p,求x的最小非负整数解. 在p是质数的情况下,这个问题比較简单. A^x=B(mod P) (P is a Prime, A,B<P) Let m = ...

  3. 我在SharePoint行业的从业经历(二)

     本文是我的SharePoint从业经历的第二篇,第一篇请參考 我在SharePoint行业的从业经历(一) 做完那个项目之后.对SharePoint 2003有了一些认识. 可是后来几年我就没在 ...

  4. SQL 优化记录

    1. 对Where 语句的法则 1.1 避免在WHERE子句中使用in,not  in,or 或者having. 可以使用 exist 和not exist代替 in和not in. 可以使用表链接代 ...

  5. UESTC--1251--谕神的密码(贪心)

     谕神的密码 Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu Submit Status ...

  6. bzoj4977 跳伞求生——贪心

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4977 今天讲的贪心题,真神奇啊: 首先,要得到尽量多选队友的解: 把队友按 a[i] 从小到 ...

  7. 10 Future Web Trends 十大未来互联网趋势

    转载自:http://blog.sina.com.cn/s/blog_4be577310100ajpb.html 我们很满意自己进入的当前网络纪元,通常被称为Web 2.0.这个阶段互联网的特征包括搜 ...

  8. HTML 14 JS事件

    一 :什么是事件 发生的某一件事:触发特定的条件,完成某一项功能 二:学习的目的 在特定的条件下,完成特定的功能 条件满足的情况下,系统会自动执行 ( 回调 ) 绑定的方法 学习要点: 1.事件的两种 ...

  9. C#将文件压缩成一个文件流,供前端下载

    直接上代码供大家参考... 前端页面就是一个下载的Button.. <body> <form id="form1" runat="server" ...

  10. windows phone控件

    常用控件: 包括: Button控件.CheckBox控件.HyperlinkButton控件.Iamege控件.ListBox控件.PasswordBox控件.ProgressBar控件.Radio ...