Codeforces Tell Your World
来源:互联网 发布:java string类源码分析 编辑:程序博客网 时间:2024/05/29 15:24
题意:
求给出的点,判断所有点是否都在两条平行线上。第一个点和第二个点的斜率k1,第二个点和第三个点的斜率k2,第一个点和第三个点斜率k3,三个点肯定有两个点在一条直线上,所以三个斜率总有一个是真正的斜率,以第一个点和第二个点作为基准点,判断是否满足斜率相同。代码参考了一位大佬的。
Connect the countless points with lines, till we reach the faraway yonder.
There are n points on a coordinate plane, the i-th of which being (i, yi).
Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set.
The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points.
The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109) — the vertical coordinates of each point.
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise.
You can print each letter in any case (upper or lower).
57 5 8 6 9
Yes
5-1 -2 0 0 -5
No
55 4 3 2 1
No
51000000000 0 0 0 0
Yes
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one.
In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel.
In the third example, it's impossible to satisfy both requirements at the same time.
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<queue>#include<set>#include<map>#include<cmath>using namespace std;#define maxn 1000005typedef long long ll;int n;int y[1005];bool solve(double k){ int flag=0; int point=-1; for(int i=2;i<=n;i++) { if(y[i]-y[1]==k*(i-1)) continue; flag=1; if(point<0) point=i; else if(y[i]-y[point]!=(i-point)*k) { flag=0; break; } } if(flag) return true; else return false;}int main(){ cin>>n; for(int i=1;i<=n;i++) cin>>y[i]; double k1=(y[2]-y[1])*1.0; double k2=(y[3]-y[2])*1.0; double k3=(y[3]-y[1])*0.5; if(solve(k1)||solve(k2)||solve(k3)) cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0;}
- Codeforces Tell Your World
- Codeforces 849 B Tell Your World
- CodeForces 849B Tell Your World 点线
- codeforces 849B. Tell Your World
- codeforces 849B Tell Your World
- Codeforces-849B Tell Your World
- Codeforces 894B. Tell Your World
- Codeforces849B Tell Your World
- Codeforces Round #431 (Div. 2) Tell Your World
- Codeforces Round #431 (Div. 2) B. Tell Your World
- codeforces 849B Tell Your World(计算几何)
- Codeforces 849 B. Tell Your World(计算几何)
- Codeforces 849B. Tell Your World 计算几何
- Codeforces Round #431 (Div. 2)B Tell Your World
- Codeforces Round #431 (Div. 2) B. Tell Your World(向量积)
- Codeforces Round #431 (Div. 2) 849B Tell Your World(暴力+枚举)
- Codeforces Round #431 (Div. 2) B. Tell Your World(技巧性模拟+精度坑死人系列)
- B. Tell Your World Codeforces Round #431 (Div. 2)(简单模拟)
- VC对话框添加菜单快捷键
- 第一篇
- web安全方向
- Coursera吴恩达《神经网络与深度学习》课程笔记(1)-- 深度学习概述
- Codeforces Round #431 (Div. 2) From Y to Y
- Codeforces Tell Your World
- 【codevs 1036】商务旅行
- Guava Cache使用笔记
- git 如何正确的提交文件
- cf 849B
- 欢迎使用CSDN-markdown编辑器
- git 使用详细介绍
- 快速排序及c++实现
- 大话设计模式之一:如何在visual studio 中建立C#程序