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

这题看了高手的代码才会。

题意:给出n个点的坐标,问这n个点能否在都在两条平行的直线上。

(注意题面第二行给出了横坐标- - 我都是一直以为没有横坐标,读了好久题才发现)

解题思路:两条平行线的斜率k是一样的,对前三个坐标a[1],a[2],a[3]进行处理,因为要求每个点都在线上,那么这三个点之间的斜率:

k1=a[2]-a[1];

k2=a[3]-a[2];

k3=(a[3]-a[1])/2;

肯定至少有一个是直线的真正斜率(这点可以画个图仔细想想),再根据直线方程y=kx+b,把这三个斜率对所有点套一下,如果只有

两个不相等的b值,则输出Yes,否则输出No。

附代码:

  1. 1 #include <cstdio>
  2. 2 #include <cstring>
  3. 3 #include <algorithm>
  4. 4 #include <set>
  5. 5 using namespace std;
  6. 6 const int M = 1111;
  7. 7 double nu[M];
  8. 8 int n;
  9. 9 bool solve(double k){
  10. 10 set<double>s;
  11. 11 for(int i=1;i<=n;i++){
  12. 12 s.insert(nu[i]-i*k);
  13. 13 }
  14. 14 return s.size()==2;
  15. 15 }
  16. 16 int main(){
  17. 17 scanf("%d",&n);
  18. 18 for(int i=1; i<=n; i++) scanf("%lf",&nu[i]);
  19. 19 if(solve(nu[2]-nu[1]) || solve(nu[3]-nu[2]) || solve((nu[3]-nu[1])/2))
  20. 20 printf("Yes");
  21. 21 else printf("No");
  22. 22 return 0;
  23. 23 }

codeforce 849B的更多相关文章

  1. Codeforce - Street Lamps

    Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...

  2. Codeforce Round #216 Div2

    e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...

  3. Codeforce 水题报告(2)

    又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...

  4. codeforce 375_2_b_c

    codeforce 375_2 标签: 水题 好久没有打代码,竟然一场比赛两次卡在边界条件上....跪 b.题意很简单...纯模拟就可以了,开始忘记了当字符串结束的时候也要更新两个值,所以就错了 #i ...

  5. codeforce 367dev2_c dp

    codeforce 367dev2_c dp 标签: dp 题意: 你可以通过反转任意字符串,使得所给的所有字符串排列顺序为字典序,每次反转都有一定的代价,问你最小的代价 题解:水水的dp...仔细想 ...

  6. 三维dp&codeforce 369_2_C

    三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...

  7. 强连通分量&hdu_1269&Codeforce 369D

    强连通分量 标签: 图论 算法介绍 还记得割点割边算法吗.回顾一下,tarjan算法,dfs过程中记录当前点的时间戳,并通过它的子节点的low值更新它的low,low值是这个点不通过它的父亲节点最远可 ...

  8. 【树状数组】区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D

    [树状数组]区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D PROBLEM 题目描述 初始给定n个卡片拍成一排,其中第i个卡片上的数为x[i]. 有q个询问,每次询问 ...

  9. 解题报告:codeforce 7C Line

    codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...

随机推荐

  1. SpringBoot JPA简单使用

    引自B站楠哥:https://www.bilibili.com/video/BV137411B7vB 一.新建Springboot项目 ​ pom.xml文件 <?xml version=&qu ...

  2. Python干货:了解元组与列表的使用和区别

    元组是 Python 对象的集合,跟列表十分相似.下面进行简单的对比. 列表与元组 1.python中的列表list是变量,而元组tuple是常量. 列表:是使用方括号[],元组:则是使用圆括号() ...

  3. Jmeter5.1.1 把默认语言调整为中文

    进入安装目录:apache-jmeter-5.1.1\bin\ 找到 jmeter.properties文件 搜索" language=en ",前面带有"#" ...

  4. connection-backoff ConnectionBackoff Strategy 回退

    grpc/connection-backoff.md at master · grpc/grpc https://github.com/grpc/grpc/blob/master/doc/connec ...

  5. 关于notepad++不能设置中文的解决方法

    好久没用notepad++了,最近遇到一个base64的音频文件,想起来notepad++挺好用的 于是安装好 然后发现 最新的notepad++竟然不能显示中文界面 这怎么可以呢! 上网搜 果然 作 ...

  6. loj10172

    涂抹果酱 Tyvj 两周年庆典要到了,Sam 想为 Tyvj 做一个大蛋糕.蛋糕俯视图是一个 N×M 的矩形,它被划分成 N×M 个边长为 1×1 的小正方形区域(可以把蛋糕当成 NNN 行 MMM  ...

  7. Language Guide (proto3) | proto3 语言指南(十五)生成类

    Generating Your Classes - 生成类 要生成Java.Python.C++.Go.Ruby.ObjuleC或C代码,需要使用.proto文件中定义的消息类型,还需要在.proto ...

  8. 四:SpringBoot-定时任务和异步任务的使用方式

    SpringBoot-定时任务和异步任务的使用方式 1.定时任务 2.同步和异步 3.定时器的使用 3.1 定时器执行规则注解 3.2 定义时间打印定时器 3.3 启动类开启定时器注解 4.异步任务 ...

  9. CVE-2020-1472 域内提权

    攻击者通过NetLogon(MS-NRPC),建立与域控间易受攻击的安全通道时,可利用此漏洞获取域管访问权限.成功利用此漏洞的攻击者可以在该网络中的设备上运行经特殊设计的应用程序. 影响版本 Wind ...

  10. js创建map

    function Map() { var struct = function(key, value) { this.key = key; this.value = value; } var put = ...