849BTell Your World
来源:互联网 发布:淘宝上有哪些零食神殿 编辑:程序博客网 时间:2024/06/10 16:52
849B Tell Your World
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.
Input
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
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).
Examples
input
5
7 5 8 6 9
output
Yes
input
5
-1 -2 0 0 -5
output
No
input
5
5 4 3 2 1
output
No
input
5
1000000000 0 0 0 0
output
Yes
Note
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.
这道题当时想的时候怎么也想不出来……..放到B题这么位置,以后千万不敢多想,直接上暴力,这道题知道前3个点以后,肯定能求出斜率, 因为肯定有两个点会构成一条直线符合条件,然后我们枚举前三个点构成的斜率,然后再从第二个点开始依次与第一个点比较,如果跟第一个点的斜率不符合原来假设的斜率就说明这个点要么是第二条直线的起点,要么就构不成直线,这三个斜率只要有一个符合条件都可以
#include<bits/stdc++.h>using namespace std;int ans[1005],n;bool check(double k) { int point=-1,flag=0; for(int i=2;i<=n;i++) { if((ans[i]-ans[1])==k*(i-1)) continue; flag=1; if(point==-1) point=i; if((ans[i]-ans[point])!=k*(i-point)) { flag=0; break; } } if(flag==1) return true; else return false;}int main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n; for(int i=1;i<=n;i++) cin>>ans[i]; double k1=1.0*(ans[2]-ans[1]); double k2=0.5*(ans[3]-ans[1]); double k3=1.0*(ans[3]-ans[2]); if(check(k1)||check(k2)||check(k3)) cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0;}
- 849BTell Your World
- 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
- start your world here
- Codeforces Tell Your World
- Codeforces849B Tell Your World
- CodeFroces 849B. Tell Your World (鸽巢原理)
- codeforces 849B Tell Your World(计算几何)
- Codeforces 849 B. Tell Your World(计算几何)
- Codeforces 849B. Tell Your World 计算几何
- Codeforces Round #431 (Div. 2) 849B Tell Your World(暴力+枚举)
- CodeForces #431Div. 2 849B Tell your world 几何 暴力 枚举
- maximize your World of Warcraft demo time
- Hello World! Build Your First iPhone App
- Solr6.6安装教程
- hibernate--1+N问题(典型问题)
- MATLAB --画图
- 全球第一个云端WebRTC编译系统
- 198. House Robber
- 849BTell Your World
- Spring Boot学习--项目启动时执行特定方法
- master communication with slave each other
- 线段树
- linux golang环境
- 自定义控件的自定义属性
- 搭建自动化测试平台(selenium+testng+maven+svn+Jenkins)【转自galen2016】
- python爬虫学习第三十九天
- 新手使用hibernate遇到的问题(1)