Codeforces 849B Tell Your World (计算几何)
题目链接 Tell Your World
题意 给出N个点(i, xi),问是否存在两条平行的直线,使得每一个点恰好在两条直线的其中一条上。
每条直线必须穿过至少一个点。
考虑每个点和第1个点的斜率,相同的用并查集弄成一个连通块。
然后我们枚举每个连通块,判断不在连通块内的这些点是否在同一条直线上,且斜率必须满足和另一条相等。
注意特殊情况
1号点单独占一条直线,其他的点占另一条直线。
这种情况样例里就有。
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i) typedef long long LL; const int N = 1e3 + 10;
const double eps = 1e-8; LL a[N];
int father[N], b[N], c[N], f[N];
int n, cnt = 0, ans = 0;
double cc[N];
vector <int> v[N]; int getfather(int x){ return father[x] ? father[x] = getfather(father[x]) : x;} int main(){ scanf("%d", &n);
rep(i, 1, n) scanf("%lld", a + i); rep(i, 2, n - 1){
rep(j, i + 1, n){
if ((LL)(i - 1) * (a[j] - a[1]) == (LL)(j - 1) * (a[i] - a[1])){
int fa = getfather(i), fb = getfather(j);
if (fa ^ fb){
father[fa] = fb;
}
}
}
} rep(i, 2, n){
int x = getfather(i);
if (!c[x]){
c[x] = ++cnt;
v[cnt].push_back(i);
}
else v[c[x]].push_back(i);
} ans = 0;
rep(i, 1, cnt){
if ((int)v[i].size() == n - 1) continue;
memset(b, 0, sizeof b);
double AA = (double)(a[v[i][0]] - a[1]) / (v[i][0] - 1);
for (auto u : v[i]) b[u] = 1;
int now = 0;
rep(j, 2, n) if (!b[j]) f[++now] = j;
if (now == 1){
ans = 1;
break;
} int ff = 0;
rep(j, 2, now) cc[++ff] = (double)(a[f[j]] - a[f[1]]) / (double)(f[j] - f[1]); sort(cc + 1, cc + ff + 1);
bool fl = true;
rep(j, 1, ff - 1) if (fabs(cc[j + 1] - cc[j]) > eps){
fl = false;
continue;
} if (!fl) continue;
if (fabs(AA - cc[1]) < eps){
ans = 1;
break;
} } int ff = 0;
rep(j, 3, n) cc[++ff] = (double)(a[j] - a[2]) / (double)(j - 2); sort(cc + 1, cc + ff + 1);
bool fl = true;
rep(j, 1, ff - 1) if (fabs(cc[j + 1] - cc[j]) > eps){
fl = false;
break;
} if (fl){
double AA = (double)(a[2] - a[1]);
if (fabs(AA - cc[1]) > eps) ans = 1;
}
puts(ans ? "Yes" : "No");
return 0;
}
Codeforces 849B Tell Your World (计算几何)的更多相关文章
- Codeforces 659D Bicycle Race【计算几何】
题目链接: http://codeforces.com/contest/659/problem/D 题意: 若干条直线围城的湖,给定直线的端点,判断多少个转点会有危险?(危险是指直走的的话会掉进水里) ...
- Codeforces 340B - Maximal Area Quadrilateral (计算几何)
Codeforces Round #198 (Div. 2) 题目链接:Maximal Area Quadrilateral Iahub has drawn a set of \(n\) points ...
- Codeforces Gym 100338B Geometry Problem 计算几何
Problem B. Geometry ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
- Codeforces 1045E. Ancient civilizations 构造 计算几何 凸包
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1045E.html 4K码量构造题,CF血腥残暴! 题解 首先,如果所有点颜色相同,那么直接连个菊花搞定. ...
- Codeforces 1079D Barcelonian Distance(计算几何)
题目链接:Barcelonian Distance 题意:给定方格坐标,方格坐标上有两个点A,B和一条直线.规定:直线上沿直线走,否则沿方格走.求A到B的最短距离. 题解:通过直线到达的:A.B两点都 ...
- codeforces 672C C. Recycling Bottles(计算几何)
题目链接: C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces 499C:Crazy Town(计算几何)
题目链接 给出点A(x1,y1),B(x2,y2),和n条直线(ai,bi,ci,aix + biy + ci = 0),求A到B穿过多少条直线 枚举每条直线判断A.B是否在该直线两侧即可 #incl ...
- CodeForces - 849B 几何
题意:给n个点,问是否能两条平行线覆盖所有的点 思路:因为要求全部覆盖,所以我们第一个点肯定是会入其中一条直线,其实只用判前三个点的所有情况即可 #include<stdio.h> #in ...
- Codeforces Round #335 (Div. 1) C. Freelancer's Dreams 计算几何
C. Freelancer's Dreams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contes ...
随机推荐
- 快学UiAutomator配置编辑环境
Java环境配置 1.下载jdk1.6+包 2.安装jdk,默认安装即可 3.成功安装之后,进行测试是否真的成功安装,点击[开始]----[运行]----输入 CMD,在命令提示符里面输入“Java ...
- C++ _ const的用法,特别是用在函数前面与后面的区别!
在普通的非 const成员函数中 this的类型是一个指向类类型的 const指针.可以改变this所指向的值,但不能改变 this所保存的地址. 在 const成员函数中 this的类型是一个指向 ...
- C05 C语言字符串和数组
目录 数组 字符串 数组 概念 数组是有序数据的集合. 数组中的每一个元素属于同一个数据类型. 通过数组名和下标唯一确定数组中的元素. 一维数组的定义 语法格式 数据类型 数组名[常量表达式] 例 ...
- 用Kotlin开发android平台语音识别,语义理解应用(olamisdk)
Kotlin是由JetBrains创建的基于JVM的编程语言,IntelliJ正是JetBrains的杰作,而android Studio是 基于IntelliJ修改而来的.Kotlin是一门包含很多 ...
- ratio_to_report分析函数求占比
drop table test; create table test ( name varchar(20), kemu varchar(20), score number ); insert int ...
- Ukulele 原来你也在这里
- 【二分】bestcoder p1m2
模型的转化和二分check的细节挺不错的 Problem Description 度度熊很喜欢数组!! 我们称一个整数数组为稳定的,若且唯若其同时符合以下两个条件: 数组里面的元素都是非负整数. 数组 ...
- Android Studio问题记录
1>Android Studio中module是什么,? 答:Android Studio是基于intellij,跟eclipse不太一样.对应关系如下: intellij的project -- ...
- (49)zabbix事件是什么?事件来源有哪些分类
什么是zabbix 事件 在trigger的文章内,我们已经有用到事件,这个事件要讲概念真心不知道怎么说,就拿trigger事件来说,如果trigger从当前值ok转变为problem,那么我们称之为 ...
- verilog behavioral modeling--procedural continous assignment(不用)
assign / deassgin force /release the procedural continuous assignments(using keywords assign and for ...