博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
B. Tell Your World(几何数学 + 思维)
阅读量:5087 次
发布时间:2019-06-13

本文共 2523 字,大约阅读时间需要 8 分钟。

B. Tell Your World
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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
Copy
5 7 5 8 6 9
output
Copy
Yes
input
Copy
5 -1 -2 0 0 -5
output
Copy
No
input
Copy
5 5 4 3 2 1
output
Copy
No
input
Copy
5 1000000000 0 0 0 0
output
Copy
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.

 

算法:几何数学 + 思维

 

#include 
#include
#include
using namespace std;typedef long long ll;#define INF 0x3f3f3f3fconst int maxn = 1e5+7;ll a[maxn];int n;int solve(double k) { int pos = -1; for(int i = 2; i <= n; i++) { if(a[i] - a[1] == (i - 1) * k ) { continue; } if(pos == -1) { pos = i; //确定一个新的基点 } else if(a[i] - a[pos] != (i - pos) * k){ return 0; } } return pos != -1; //判断是否是所有的点都在一条直线上}int main() { while(~scanf("%d", &n)) { for(int i = 1; i <= n; i++) { cin >> a[i]; } //以三点来确定三条直线,有以下三种情况 double k1 = a[2] - a[1]; double k2 = 1.0 * (a[3] - a[1]) / 2; double k3 = a[3] - a[2]; if(solve(k1) || solve(k2) || solve(k3)) { printf("Yes\n"); } else { printf("No\n"); } } return 0;}

 

 

转载于:https://www.cnblogs.com/buhuiflydepig/p/11312083.html

你可能感兴趣的文章
【BZOJ 5222】[Lydsy2017省队十连测]怪题
查看>>
第二次作业
查看>>
【input】 失去焦点时 显示默认值 focus blur ★★★★★
查看>>
Java跟Javac,package与import
查看>>
day-12 python实现简单线性回归和多元线性回归算法
查看>>
Json格式的字符串转换为正常显示的日期格式
查看>>
[转]使用 Razor 进行递归操作
查看>>
[转]Android xxx is not translated in yyy, zzz 的解决方法
查看>>
docker入门
查看>>
Android系统--输入系统(十一)Reader线程_简单处理
查看>>
监督学习模型分类 生成模型vs判别模型 概率模型vs非概率模型 参数模型vs非参数模型...
查看>>
Mobiscroll脚本破解,去除Trial和注册时间限制【转】
查看>>
实验五 Java网络编程及安全
查看>>
32位与64位 兼容编程
查看>>
iframe父子页面通信
查看>>
ambari 大数据安装利器
查看>>
java 上传图片压缩图片
查看>>
magento 自定义订单前缀或订单起始编号
查看>>
ACM_拼接数字
查看>>
计算机基础作业1
查看>>