B. Tell Your World(几何数学 + 思维)

时间:2023-01-21 13:51:39
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&num;为例)

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

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

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

  3. UVa10025 The &quest; 1 &quest; 2 &quest; &period;&period;&period; &quest; n &equals; k problem 数学思维&plus;规律

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

  4. C&period; Polygon for the Angle 几何数学

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

  5. hdu 4710 Balls Rearrangement &lpar;数学思维&rpar;

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

  6. F&period; Multicolored Markers(数学思维)

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

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

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

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

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

  9. Wannafly交流赛1 B &Tab;硬币&lbrack;数学思维&sol;贪心&rsqb;

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

随机推荐

  1. 【转】android中最好的瀑布流控件PinterestLikeAdapterView

    [源地址]http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/0919/1696.html 之前我们介绍过一个开源的瀑布流控件Stag ...

  2. HttpListener supports SSL only for localhost&quest; install certificate

    1.Start-All Programs - 2.execute below lines on that ‘Developer Command Prompt..’ tool makecert -n & ...

  3. ionic&plus;angulajs

    基于ionic+angulajs的混合开发实现地铁APP 项目源码地址:https://github.com/zhangxy1035/SubwayMap 一.项目简介 在该项目中的地铁app是基于io ...

  4. 【实习记】2014-08-10&lpar;上&rpar;代码跟踪git的想法&plus;归并排序的debug过程

        (冒泡,选择,插入,希尔,快速,归并,堆排)周末加班学习C++,打算用C++写七大经典排序代码.发现3个月前自己写的七大经典排序代码(C Language)突然运行出错. Makefile内容 ...

  5. Java程序员应该知道的10个面向对象理论

    英文原文:10-object-oriented-design-principles 面向对象理论是面向对象编程的核心,但是我发现大部分 Java 程序员热衷于像单例模式.装饰者模式或观察者模式这样的设 ...

  6. ajax文本空输入显示用户信息

    一般文件代码 public void ProcessRequest (HttpContext context) { //获取主见值 string s = context.Request["u ...

  7. 关于 js 中的 call 和 apply使用理解

    关于 js 中的 call 和 apply使用理解 在学习新的东西时候,碰到以前看过而又不理解,或则记忆不深的地方不妨回头看看书里知识点,有助于加深理解.正所谓--温故而知新. 废话不多说,直接上代码 ...

  8. RabbitMQ学习笔记(六) RPC

    什么RPC? 这一段是从度娘摘抄的. RPC(Remote Procedure Call Protocol)——远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的 ...

  9. web功能测试之表单、搜索测试

    初入职场接触功能测试老是碰到以下情况不知道怎么写测试用例: 一个界面很多搜索条件怎么写用例?下拉框测试如何考虑测试点?上传要考虑哪些验证点?...... 所以这篇主要是整理关于web测试之表单.搜索测 ...

  10. &lbrack;转&rsqb;常见的JavaScript内存泄露

    什么是内存泄露 内存泄漏指由于疏忽或错误造成程序未能释放已经不再使用的内存.内存泄漏并非指内存在物理上的消失,而是应用程序分配某段内存后,由于设计错误,导致在释放该段内存之前就失去了对该段内存的控制, ...