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. 【c语言】字符串替换空格:请实现一个函数,把字符串中的每一个空格替换成“%20”

    // 字符串替换空格:请实现一个函数,把字符串中的每一个空格替换成"%20". // 比如输入"we are happy.",则输出"we%20are ...

  2. 将TensorFlow模型变为pb——官方本身提供API,直接调用即可

    TensorFlow: How to freeze a model and serve it with a python API 参考:https://blog.metaflow.fr/tensorf ...

  3. B1789 Y型项链 贪心

    想明白之后就是一道大水题,就是两两把最长公共前缀求出来,然后直接取最长的,然后就直接暴力算就行了... 题干: Description 欢乐岛上众多新奇的游乐项目让小可可他们玩的非常开心.现在他们正在 ...

  4. aspectC++常用命令

    常用命令:1.ag++ main.cc //在工程目录下产生编译后的exe2.ag++ main.cc --weave_only //产生.acc 纯c++文件3.ag++ main.cc --gen ...

  5. LocalDateTime查找最近的五分钟点

    /** * 最近的五分钟 * @param dateTime * @return */ public static LocalDateTime getNear5(LocalDateTime dateT ...

  6. gitlab克隆报错:remote: HTTP Basic: Access denied;remote: You must use a personal access token with ‘api’ scope for Git over HTTP.

    错误: remote: HTTP Basic: Access denied remote: You must use a personal access token with ‘api’ scope ...

  7. POJ 1118 求平面上最多x点共线

    题意:给你n个点的坐标.求一条直线最多能穿过多少个点. 思路:枚举(n^2)+求斜率+排序 (复杂度n^2logn)大功告成 //By: Sirius_Ren #include <cmath&g ...

  8. Cloudera Manager安装之利用parcels方式(在线或离线)安装单节点集群(包含最新稳定版本或指定版本的安装)(添加服务)(Ubuntu14.04)(四)

    .. 欢迎大家,加入我的微信公众号:大数据躺过的坑     免费给分享       同时,大家可以关注我的个人博客:  http://www.cnblogs.com/zlslch/   和  http ...

  9. iOS - CocoaPods操作详解

    在我们进行iOS应用开发的时候,肯定会用到很多的第三方类库,最常用AFNetworking,SDWebImage等等,当我们用到这个类库的时候,就要一个一个的去下载这个类库,如果这个类库中又用到了其他 ...

  10. 《CSS Mastery》 读书笔记 (1)

    --本笔记中英混合,专业名词尽量不翻译,免得误解,如果不习惯,就不用往下看了,走好不送. 第一章 基础 人类的好奇心总是促使我们捣鼓,捣鼓是最好做有效的学习CSS的方法 In this chapter ...