题目链接 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 (计算几何)的更多相关文章

  1. Codeforces 659D Bicycle Race【计算几何】

    题目链接: http://codeforces.com/contest/659/problem/D 题意: 若干条直线围城的湖,给定直线的端点,判断多少个转点会有危险?(危险是指直走的的话会掉进水里) ...

  2. Codeforces 340B - Maximal Area Quadrilateral (计算几何)

    Codeforces Round #198 (Div. 2) 题目链接:Maximal Area Quadrilateral Iahub has drawn a set of \(n\) points ...

  3. Codeforces Gym 100338B Geometry Problem 计算几何

    Problem B. Geometry ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

  4. Codeforces 1045E. Ancient civilizations 构造 计算几何 凸包

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF1045E.html 4K码量构造题,CF血腥残暴! 题解 首先,如果所有点颜色相同,那么直接连个菊花搞定. ...

  5. Codeforces 1079D Barcelonian Distance(计算几何)

    题目链接:Barcelonian Distance 题意:给定方格坐标,方格坐标上有两个点A,B和一条直线.规定:直线上沿直线走,否则沿方格走.求A到B的最短距离. 题解:通过直线到达的:A.B两点都 ...

  6. codeforces 672C C. Recycling Bottles(计算几何)

    题目链接: C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  7. Codeforces 499C:Crazy Town(计算几何)

    题目链接 给出点A(x1,y1),B(x2,y2),和n条直线(ai,bi,ci,aix + biy + ci = 0),求A到B穿过多少条直线 枚举每条直线判断A.B是否在该直线两侧即可 #incl ...

  8. CodeForces - 849B 几何

    题意:给n个点,问是否能两条平行线覆盖所有的点 思路:因为要求全部覆盖,所以我们第一个点肯定是会入其中一条直线,其实只用判前三个点的所有情况即可 #include<stdio.h> #in ...

  9. 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 ...

随机推荐

  1. golang 强制重新全部编译

    /home/用户名/.cache 删除缓存试试?? 修改的东西老失败 编译结果总不变 神奇了 go build -a    -x -v加一句-a 强制重新编译.

  2. easyui树节点拖拽排序的存储过程

    easyui树的拖拽排序功能 easyui树中有拖拽功能 树结构如下: 一个行政区域对应一个单位,一个单位对应多个部门,每个部门下有相关人员,功能要求: (1)行政区域没有子节点,点击text加载部门 ...

  3. 带图形桌面的CentOS7----中安装VMWareTools以及支持中文输入

    主机是WIN10操作系统 安装VMWareTools的方法:https://jingyan.baidu.com/article/e8cdb32b136ad637052bad26.html 在图形化Ce ...

  4. grafana绘制图表

    安装方法 系统为ubuntu16 1首先添加以下到/etc/apt/sources.list: deb https://packagecloud.io/grafana/stable/debian/ s ...

  5. springboot的启动类不能直接放在src/java目录下,不然会报错

    jar包的application.yml 会被项目的覆盖,导致找不到原有的配置

  6. 如何用纯 CSS 创作一个记事本翻页动画

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/qKOPGw 可交互视频教 ...

  7. Python之路-基础数据类型之列表 元组

    列表的定义 列表是Python基础数据类型之一,它是以[ ]括起来, 每个元素用' , '隔开而且可以存放各种数据类型: lst = [1,2,'你好','num'] 列表的索引和切片 与字符串类似, ...

  8. include/autoconfig.mk

    把autoconfig.mk和/include/configs/ $(obj)include/autoconf.mk.dep: $(obj)include/config.h include/commo ...

  9. go的相关用法

    1. have gone to和have been to的区别 have gone to和have been to的区别如下: 1.have gone to,第三人称时用 has gone to ha ...

  10. python 跨域

    CORS跨域请求 CORS即Cross Origin Resource Sharing 跨域资源共享, 那么跨域请求还分为两种,一种叫简单请求,一种是复杂请求~~ 简单请求 HTTP方法是下列方法之一 ...