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

B. Tell Your World(几何数学 + 思维)的更多相关文章

  1. 程序设计中的数学思维函数总结(代码以C#为例)

    最近以C#为例,学习了程序设计基础,其中涉及到一些数学思维,我们可以巧妙的将这些逻辑问题转换为代码,交给计算机运算. 现将经常会使用到的基础函数做一总结,供大家分享.自己备用. 1.判断一个数是否为奇 ...

  2. PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记

    PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...

  3. UVa10025 The ? 1 ? 2 ? ... ? n = k problem 数学思维+规律

    UVa10025 ? 1 ? 2 ? ... ? n = k problem The problem Given the following formula, one can set operator ...

  4. C. Polygon for the Angle 几何数学

    C. Polygon for the Angle 几何数学 题意 给出一个度数 ,问可以实现的最小的n的n边形是多少 思路 由n边形的外角和是180度直接就可以算出最小的角是多少 如果给出的度数是其最 ...

  5. hdu 4710 Balls Rearrangement (数学思维)

    意甲冠军:那是,  从数0-n小球进入相应的i%a箱号.然后买一个新的盒子. 今天的总合伙人b一个盒子,Bob试图把球i%b箱号. 求复位的最小成本. 每次移动的花费为y - x ,即移动前后盒子编号 ...

  6. F. Multicolored Markers(数学思维)

    思维:思维就是将大的矩形放在小矩形里面,让大矩形的宽和长尽量靠近. 很容易得到 (a+b)% i = 0 的话, 保证了大矩形的形成,同时里面表示了两种情况:1, a % i =0, b % i=0; ...

  7. Pythagorean Triples毕达哥斯拉三角(数学思维+构造)

    Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pytha ...

  8. HDU - 6409:没有兄弟的舞会(数学+思维)

    链接:HDU - 6409:没有兄弟的舞会 题意: 题解: 求出最大的 l[i] 的最大值 L 和 r[i] 的最大值 R,那么 h 一定在 [L, R] 中.枚举每一个最大值,那么每一个区间的对于答 ...

  9. Wannafly交流赛1 B 硬币[数学思维/贪心]

    链接:https://www.nowcoder.com/acm/contest/69/B来源:牛客网 蜥蜴的生日快到了,就在这个月底! 今年,蜥蜴的快乐伙伴之一壁虎想要送好多个1元硬币来恶整蜥蜴. 壁 ...

随机推荐

  1. 怎样终止(杀掉) Linux 中的进程?

    使用 kill -9 进程号 命令, 可是强行终止该进程. 如果使用直接使用 kill 进程号 命令, 则会让进程 "自行了断" . 因此, 一般是 kill -9 进程号 用得较 ...

  2. Android中如何判断内存卡是否存在

    if (Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) { /* 得到SD卡得路 ...

  3. python之输入一系列整数输出最大值

    在python学习中,我们经常会遇到:编写一个程序,输入若干整数或者是在一串字符中,输出最大值(数)的问题.那么在这里,我给出了几种常见的,也是几种比较常用的方法,希望能给大家的学习带来一定的帮助. ...

  4. promise使用的正确方式

    一开始恨不能理解下面的代码,为什么可以一直then下去,什么时候要直接return  xxx,什么时候return 一个promise,什么时候用Promise.resolve() function ...

  5. json字符串对象

    1.将字符串转为json对象:JSON.parse(); 2.json对象转字符串:JSON.stringify(); <!DOCTYPE html> <html> <h ...

  6. 如何源码编译安装并控制nginx

    安装nginx 注意 Linux操作系统需要2.6及其以上的内核(支持epoll) 使用nginx的必备软件 gcc编辑器 yum -y install gcc gcc-c++ pcre库(支持正则表 ...

  7. TensorFlow中CNN的两种padding方式“SAME”和“VALID”

    来源 dilation_rate为一个可选的参数,默认为1,这里我们可以先不管它. 整理一下,对于"VALID",输出的形状计算如下: new_height=new_width=⌈ ...

  8. JavaJDBC【七、JDBC升级版简介】

    Commons-dbutils Apache提供的一个开源JDBC工具类库,对传统操作数据库的类进行二次封装,可以把结果集转换成List. 特点: 1.杜绝资源泄漏 2.简化代码 3.以Bean实例形 ...

  9. odoo 权限文件说明

    id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink (权限的定义)access_book_user ...

  10. apache2.4.9编译安装

    源码编译安装 由于centos7的版本可以支撑所以在centos6上编译安装 centos6 准备 gzip wget 安装 yum install gzip wget -y apr . apr-ut ...