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. Java EE javax.servlet ServletContainerInitializer接口

    ServletContainerInitializer接口 public interface ServletContainerInitializer 一.介绍 该接口,允许在 web 应用程序的启动阶 ...

  2. CSM(Certified Scrum Master) 敏捷认证是什么?

    Scrum 是用于开发和持续支持复杂产品的一个框架.Scrum 基于试验性过程控制理论,借鉴了精益思想.时间盒.模块化设计等,并完整地体现了敏捷宣言和敏捷原则.Scrum 采用一种迭代.增量式的方法来 ...

  3. springMVC 接受map参数的写法

    <form > <input type="hidden" name="map['userKey']" value="11111&qu ...

  4. C#实现鼠标滚筒缩放界面的效果

    elementCanvas继承UserControl 声明属性: #region 缩放属性添加 float ratio = 1.0f; public float Ratio { set { ratio ...

  5. 解决 Ubuntu 19 安装openjdk 8后与openjfx不兼容

    小淘气放假了,孩子在上幼儿园的小朋友,报班也不能太变态嘛, 还是让他自己娱乐的时间多一点,但是现在在家的娱乐就是看电视,听说电视看多了越看越傻,就想方设法的给他找一点娱乐活动,把我闲置的树莓派给他装了 ...

  6. Shiro学习笔记总结,附加" 身份认证 "源码案例(一)

    Shiro学习笔记总结 内容介绍: 一.Shiro介绍 二.subject认证主体 三.身份认证流程 四.Realm & JDBC reaml介绍 五.Shiro.ini配置介绍 六.源码案例 ...

  7. tftp client命令示例

    tftp 192.168.1.1 -c put myfile theirfile tftp 192.168.1.1 -m binary -c put myfile theirfile The tftp ...

  8. 7.JVM技术_java监控工具使用

    1.java监控工具使用 2.jconsole jconsole是一种集成了上面所有命令功能的可视化工具,可以分析jvm的内存使用情况和线程等信息 2.1.启动jconsole 通过JDK/bin目录 ...

  9. NOIP2017 Day1 T3 逛公园

    NOIP2017 Day1 T3 更好的阅读体验 题目描述 策策同学特别喜欢逛公园.公园可以看成一张\(N\)个点\(M\)条边构成的有向图,且没有 自环和重边.其中1号点是公园的入口,\(N\)号点 ...

  10. 【AGC002 E】Candy Piles

    本来实在写不动这题 sol 了,但一想这是个经典的模型转化问题,于是就写了(.jpg) 题意 有一个序列 \(a_i\). 两人轮流操作,每次操作为二选一: 1. 把最大的 \(a_i\) 减成 \( ...