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. Spring实战(十三)Spring事务

    1.什么是事务(Transaction)? 事务是指逻辑上的一组操作,要么全部成功,要么全部失败. 事务是指将一系列数据操作捆绑成为一个整体进行统一管理.如果某一事务执行成功,则该事务中进行的所有数据 ...

  2. Open API

    OAuth和SSO都可以做统一认证登录,但是OAuth的流程比SSO复杂.SSO只能做用户的认证登录,OAuth不仅能做用户的认证登录,开可以做open api开放更多的用户资源. Open API即 ...

  3. 树莓派3B+和3B 安装64位debian GUN/Linux系统

    请直接参考如下博客: https://blog.csdn.net/u013451404/article/details/80710136 如果是3B的树莓派用户,只需要把第一个分区boot里的.dtb ...

  4. js ajax return false了,仍然会往下执行

    function checkMust(){ var flag=false; $.getJSON("../Ajax/Carton/Ajax_TMSOrder_Create.ashx?r=&qu ...

  5. windows上pip安装及使用详解

    windows上pip安装及使用详解 2018-11-21 19:49:58 十二笔 阅读数 8229更多 分类专栏: Python学习   版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA ...

  6. Ruby 参考教程

    Ruby 参考教程 https://www.ruby-lang.org/zh_cn/documentation/ http://ruby-doc.org/docs/ https://ruby-chin ...

  7. java后台读取配置文件

    前几天开发时遇到一个问题,在后台读取配置文件的时候无法读取属性值,于是上网查了查,现在在这分享给大家: 先附上代码吧: package com.shafei.util; import java.io. ...

  8. WebStorm 启动时提示Failed to load JVM DLL

    环境:win7 64位:时间:2019-11-18 问题描述 启动webstorm 时提示failed to load JVM DLL 解决方法 启动时快捷方式要选到64位的exe

  9. mint-ui下拉加载(项目实例)

    <template> <div class="share"> <div class="header"> <div cl ...

  10. Redis01——Redis产生背景

    Redis 产生背景 1.1.数据存储的发展史 1.1.1.磁盘时代 很久之前,我们的数据存储方式是磁盘存储,每个磁盘都有一个磁道.每个磁道有很多扇区,一个扇区接近512Byte. 磁盘的寻址速度是毫 ...