codeforce 849B
1 second
256 megabytes
standard input
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.
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 "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).
5
7 5 8 6 9
Yes
5
-1 -2 0 0 -5
No
5
5 4 3 2 1
No
5
1000000000 0 0 0 0
Yes
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 #include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4 #include <set>
5 using namespace std;
6 const int M = 1111;
7 double nu[M];
8 int n;
9 bool solve(double k){
10 set<double>s;
11 for(int i=1;i<=n;i++){
12 s.insert(nu[i]-i*k);
13 }
14 return s.size()==2;
15 }
16 int main(){
17 scanf("%d",&n);
18 for(int i=1; i<=n; i++) scanf("%lf",&nu[i]);
19 if(solve(nu[2]-nu[1]) || solve(nu[3]-nu[2]) || solve((nu[3]-nu[1])/2))
20 printf("Yes");
21 else printf("No");
22 return 0;
23 }
codeforce 849B的更多相关文章
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
- Codeforce Round #216 Div2
e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...
- Codeforce 水题报告(2)
又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...
- codeforce 375_2_b_c
codeforce 375_2 标签: 水题 好久没有打代码,竟然一场比赛两次卡在边界条件上....跪 b.题意很简单...纯模拟就可以了,开始忘记了当字符串结束的时候也要更新两个值,所以就错了 #i ...
- codeforce 367dev2_c dp
codeforce 367dev2_c dp 标签: dp 题意: 你可以通过反转任意字符串,使得所给的所有字符串排列顺序为字典序,每次反转都有一定的代价,问你最小的代价 题解:水水的dp...仔细想 ...
- 三维dp&codeforce 369_2_C
三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...
- 强连通分量&hdu_1269&Codeforce 369D
强连通分量 标签: 图论 算法介绍 还记得割点割边算法吗.回顾一下,tarjan算法,dfs过程中记录当前点的时间戳,并通过它的子节点的low值更新它的low,low值是这个点不通过它的父亲节点最远可 ...
- 【树状数组】区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D
[树状数组]区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D PROBLEM 题目描述 初始给定n个卡片拍成一排,其中第i个卡片上的数为x[i]. 有q个询问,每次询问 ...
- 解题报告:codeforce 7C Line
codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...
随机推荐
- [Usaco2008 Feb]Line连线游戏
题目描述 Farmer John最近发明了一个游戏,来考验自命不凡的贝茜.游戏开始的时 候,FJ会给贝茜一块画着N (2 <= N <= 200)个不重合的点的木板,其中第i个点 的横.纵 ...
- linux自定义安装位置安装jdk
注:本文系参考网络内容及本人实践得出 1 下载jdk安装包 下载地址:https://www.oracle.com/java/technologies/javase/javase-jdk8-downl ...
- Swagger-UI展示接口
简单介绍API的管理工具Swagger的UI模块. 简介:swagger ui就是一个能整合到项目中让api的注释能够生成到一个网页上.能简单测试和给前端看. 第一步:添加引用 打开NuGet程序包管 ...
- 题解 P3833 【[SHOI2012]魔法树】
题目 直通车 很显然这是个树刨的板子,树上链查询和子树查询 注意: 1.这个点的树根为 0 而不是 1 所以注意读图时点标号 +1 就解决了 2.注意数据范围\(2^{32}\) 然后板子就能过了 n ...
- BZOJ1031
前一段时间终于看明白了后缀数组,记录一下主要的做过的题目,主要的按照黄学长的BLOG作的,主要是为了记模板.原理还是上网自己查一下吧!代码会加简单的注释. ********************** ...
- 基于navicat的数据库导入导出
1.右键当前数据库,选择转储SQL文件 选择导出sql的存放路径 2.新建统一命名的数据库,右键运行SQL文件 3,.选择要导入的SQL文件后如图
- c++复习笔记(3)
这篇是各种琐碎的东西. 类的函数如果在类内部直接实现,则成为内联函数候选.类外部实现的方法,可以用inline声明,使其称为内联函数候选.但是函数是否可以成为内联函数,需要看编译器的行为.. 构造函数 ...
- Java——定时任务调度工具
一.什么是定时任务调度? 1.常用的定时调度工具:Timer和Quartz 二.Timer简介 1.Timer的定义以及架构 2.Timer示例 三.Timer的定时调度函数 1.schedule的四 ...
- 配合 jekins—springboot脚本
#!/usr/bin/bash # author : renguangyin@yingu.com current=$(cd `dirname $0`; pwd) cd ${current} ext_n ...
- DEDECMS:安装百度UEDITOR编辑器
第一步:下载相对应编辑器的版本 首先,去百度搜索"百度ueditor编辑器",然后点击进入官网,找到下载页面.找到我们想要的编辑器的版本,看自己网站的编码是UTF-8还是GBK,下 ...