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 ...
随机推荐
- 2019的hdu暑假作业(欢迎纠错)
1219 遍历计数. #include<bits/stdc++.h> #define QAQ 0 using namespace std; ]; ]; int main(){ )){ me ...
- java数字金额转化为中文金额
public static String digitUppercase(double n){String fraction[] = {"角", "分"};Str ...
- ios 注册功能研究学习
通常,移动App的注册功能通常采用手机号码注册或者邮箱帐号注册. 不过在国内这样隐私堪忧的环境下,需要手机号来注册会流失不少用户.即便是新浪微博这样的应用,需要绑定手机号也令我不信任.除非是像淘宝.支 ...
- ajax通信
AJAX即Asynchronous JavaScript and XML(异步的 JavaScript 和 XML),可以在不重新加载整个网页的基础上,对网页的某部分进行更新. XMLHttpRequ ...
- [POJ]1111 Image Perimeters
Description Technicians in a pathology lab analyze digitized images of slides. Objects on a slide ar ...
- Day17re模块和hashlib模块
re模块 正则表达式 用一些特殊符号拼凑成的规则,去字符串中匹配到符合规则的东西 为什么有正则表达式 从字符串中取出想要的数据 怎么用正则表达式 re.findall()结果存成列表 \w 匹配一个字 ...
- eclipse中新建maven项目无法添加src/main/java问题
eclipse创建maevn web项目,在选择maven_archetype_web原型后,默认只有src/main/resources这个Source Floder. 按照maven目录结构,添加 ...
- iOS 绕过https证书验证 请求数据
HTTPS和HTTP: 1.https协议需要到ca申请证书,一般免费证书很少,需要交费. 2.http是超文本传输协议,信息是明文传输,https 则是具有安全性的ssl加密传输协议. 3.http ...
- NYOJ 7 街区最短路径问题
街区最短路径问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 一个街区有很多住户,街区的街道只能为东西.南北两种方向. 住户只可以沿着街道行走. 各个街道之间的间 ...
- [android开发篇] 权限
Android 应用采用 Java 编程语言编写.Android SDK 工具将您的代码 — 连同任何数据和资源文件 — 编译到一个 APK:Android 软件包,即带有 .apk 后缀的存档文件中 ...