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 ...
随机推荐
- centos7设置sshd端口,firewall,selinux设置
https://blog.csdn.net/qq_31927797/article/details/81095829 #停止firewallsystemctl stop firewalld.servi ...
- activiti整合开发实例总结
参考手册:http://www.mossle.com/docs/activiti/ 一.applicationContext.xml中引入activiti相关配置的xml文件 <!-- begi ...
- bootstrap 两端对齐的导航
您可以在屏幕宽度大于768px时,通过在分别使用.nav .nav-tabs或.nav .nav-pills的同时使用class.nav-justified,让标签式或胶囊式导航菜单与父元素等宽,在更 ...
- js中的跨域方法总结
什么是跨域? 浏览器的安全策略,只要协议,域名,端口有任何一个不同,就被当做不同的域. 下面对http://www.qichedaquan.com的同源检测 http://www.qichedaqua ...
- 总结:JavaScript异步、事件循环与消息队列、微任务与宏任务
本人正在努力学习前端,内容仅供参考.由于各种原因(不喜欢博客园的UI),大家可以移步我的github阅读体验更佳:传送门,喜欢就点个star咯,或者我的博客:https://blog.tangzhen ...
- python3.x中的33个保留字
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32 Type " ...
- mysql5.7.22-log 修改远程访问
正常的设置账号远程访问依然访问不了的情况,可以看一下服务器 my.cnf配置文件下 [client] #password = your_password 把上面的#去掉就行了.
- rootfs注册挂载过程分析
参考:Linux Filesystem: 解析 Linux 中的 VFS 文件系统机制 主要代码, init_rootfs(); init_mount_tree(); 1.init_rootfs()解 ...
- LeetCode(103) Binary Tree Zigzag Level Order Traversal
题目 Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left ...
- stm32L011F3——串口实例
/* STM32L0xx HAL library initialization: - Configure the Flash prefetch, Flash preread and Buffer ca ...