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. @RestController注解的使用

    示例代码:/*@ResponseBody@Controller*/@RestControllerpublic class HelloController { @RequestMapping(" ...

  2. tolua reference

    Using Lua API and tag method facilities, tolua maps C/C++ constants, external variables, functions, ...

  3. Dubbo实战(一)高速入门

    Dubbo是什么? Dubbo[]是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案. 其核心部分包含: 远程通讯: 提供对多种基于长连接的NIO框架抽象封 ...

  4. hdu1704——floyd

    Problem Description there are N ACMers in HDU team.ZJPCPC Sunny Cup 2007 is coming, and lcy want to ...

  5. 【HNOI 2004】 L语言

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1212 [算法] 字典树 + dp [代码] #include<bits/std ...

  6. CPPCMS库在Windows下的使用

    标题:CPPCMS库在Windows下的使用时间:2012-7作者:Kagula 环境:[1]WinXP SP3[2]VisualStudio2008 SP1[3]ZLib 1.2.7[4]PCRE ...

  7. Java-JDK:JDK百科

    ylbtech-Java-JDK:JDK百科 JDK是 Java 语言的软件开发工具包,主要用于移动设备.嵌入式设备上的java应用程序.JDK是整个java开发的核心,它包含了JAVA的运行环境(J ...

  8. php循环跳出

    PHP中的循环结构大致有for循环,while循环,do{} while 循环以及foreach循环几种,不管哪种循环中,在PHP中跳出循环大致有这么几种方式: 代码: <?php $i = 1 ...

  9. 长脖子鹿省选模拟赛 [LnOI2019SP]快速多项式变换(FPT)

    本片题解设计两种解法 果然是签到题... 因为返回值问题T了好久... 第一眼:搜索大水题? 然后...竟然A了 #include<cstdio> #include<queue> ...

  10. 【BZOJ1306】match循环赛

    预先警告:我的做法代码量比较大 看完题目后看到数据n<=8, 不难想到这题可以写深搜来做 分析 比如说以数据: 3 3 3 3 为例子, 进行了三场比赛:AB AC BC: 我们只要搜索每场比赛 ...