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 ...
随机推荐
- Hibernate映射文件配置(hbm.xml和注解方式)
一:通过*.hbm.xml配置实体的实现方式 mappingResources用于指定少量的hibernate配置文件像这样 Xml代码 <property name="mappin ...
- 人脸识别源代码Open cv
#include <stdio.h> #include <string.h> #include "cv.h" #include "cvaux.h& ...
- HDU-2018-奶牛的故事
这题找到递推式就好写了,递推式大致是: f=n (n<=4) f=f(n-1)+f(n-3) (n>4) 其实这题的题意,我觉得是有很大的问题的,它前后说的每年年初的意思都不一样,敬请参考 ...
- mysql查询数据包太大:max_allowed_packet
查询大小: show variables like '%max_allowed_packet%'; 修改大小: set global max_allowed_packet = 1024 * 1024 ...
- 【Java_基础】java类加载过程与双亲委派机制
1.类的加载.连接和初始化 当程序使用某个类时,如果该类还未被加载到内存中,则系统会通过加载.连接.初始化三个步骤来对类进行初始化.如果没有意外,jvm将会连续完成这三个步骤,有时也把这三个步骤统称为 ...
- Web鼠标事件
mousedown:鼠标按下 mouseup:鼠标抬起 mousemove:鼠标移动 mouseout:在父元素上绑定该事件,当鼠标从父元素或者从子元素上离开时都会触发该事件 mouseleave:和 ...
- docker apache安装
文章来源: 1.添加镜像 # docker pull httpd2. 2.创建httpd文件 # mkdir /data/httpd2. 3.启动apache # docker run -it -p ...
- day21-python模块
1.时间 import time #时间戳 #计算 # print(time.time()) #1481321748.481654秒 #结构化时间---当地时间 # print(time.localt ...
- Python包,json&pickle,time&datetime,random模块
补充内容: 解决模块循环导入的两种方法:(不得已而为之,表示程序结构不够严谨) 将导入模块语句放在文件最下方 保证语句导入之前函数内代码能够被执行 将导入语句放进函数体内 使其不影响整个函数的运行 包 ...
- The North American Invitational Programming Contest 2018 D. Missing Gnomes
A family of nn gnomes likes to line up for a group picture. Each gnome can be uniquely identified by ...