Codeforces Round #431 (Div. 2) B. Tell Your World
来源:互联网 发布:内网穿透软件 linux 编辑:程序博客网 时间:2024/05/29 15:43
Connect the countless points with lines, till we reach the faraway yonder.
There are n points on a coordinate plane, thei-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 onexactly one of them, and each of them passes throughat 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 integersy1, 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 points1, 3, 5, and another one that passes through points2, 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.
题目大意:给你一堆点,问这些点能不能组成两条平行线,使这两条平行线不重合而且至少有一个点
我们以1,2,3三个点出发,分别将这三个点的斜率求出来,这么一来就只有两种情况:1、三个点都在同一直线上,2、至少有两个点在一条直线上。这么一来,我们就可以知道,肯定有两个点是在同一直线上的,这三个斜率,总有一个就是平行线的斜率,然后我们再枚举一下就好了
#include<bits/stdc++.h>using namespace std;int n;int point[1010];bool judge(double x){ int flag=0; int po=-1; for(int i=2;i<=n;i++){ //斜率公式:(y2-y1)=k*(x2-x1) if(point[i]-point[1]==x*(i-1)) continue; flag=1; if(po<0) po=i; else if(point[i]-point[po]!=x*(i-po)){ flag=0; break; } } if(flag) return true; else return false;}int main(){ cin>>n; for(int i=1;i<=n;i++) scanf("%d",&point[i]); if(judge((point[2]-point[1])*1.0)||judge((point[3]-point[1])*0.5)||judge(point[3]-point[2]*1.0)){ cout<<"Yes"<<endl; } else cout<<"No"<<endl;}
- Codeforces Round #431 (Div. 2) B. Tell Your World
- Codeforces Round #431 (Div. 2)B Tell Your World
- Codeforces Round #431 (Div. 2) 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)(简单模拟)
- Codeforces Round #431 (Div. 2) A、Odds and Ends B、Tell Your World C、From Y to Y
- CodeForces #431Div. 2 849B 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
- Codeforces Tell Your World
- codeforces 849B Tell Your World(计算几何)
- Codeforces 849 B. Tell Your World(计算几何)
- [置顶] 展讯充电管理模块浅析(一)
- 【Web前端学习笔记】CSS3_常用属性,选择器,盒子模型
- 取一个数的前几位
- Java_基础—多线程程序实现的3种方式Thread和Runnable和Callable
- BZOJ 2407: 探险/BZOJ 4398: 福慧双修 dijkstra 构造
- Codeforces Round #431 (Div. 2) B. Tell Your World
- Spark 自带 demo 的学习总结
- windows访问内网服务器(ngrok用法解析)
- CodeForces
- Elasticsearch在Centos 7上的安装与配置
- C/C++ 数据格式化
- 《伸手系列》第一集-Shiro安全认证框架的从入门到“出门”
- UVA
- 关于JQuery animate()方法