Codeforces Round #431 (Div. 2) B. Tell Your World
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.
思路:
懒得写了,暴力枚举各种情况讨论。
代码很丑,之前有两个特殊情况没判到,fst了,,直接从rank600 - 1000,是真的脏,心态爆炸。
实现代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<int,int>mp;
int main()
{
ll m,i,j,cnt,a[],b[];
cin>>m;
for(i=;i<=m;i++)
cin>>a[i];
b[] = -;
int len = ;
for(i=;i<=m;i++){
ll ans = a[i]-a[i-];
//cout<<ans<<endl;
cnt = ;
for(j=;j<len;j++)
if(ans!=b[j])
cnt++;
if(cnt == len){
b[len] = ans;len++;
}
}
len--;
//cout<<len<<endl;
if(len == ){
for(i=;i<=m;i++){
ll ans = a[i]-a[i-];
mp[ans]++;
}
if(mp[b[]]==||mp[b[]]==)
cout<<"Yes"<<endl;
else{
int flag = ;
for(i=;i<m;i++){
ll ans1 = a[i] - a[i-];
ll ans2 = a[i+] - a[i];
if(ans1+ans2>max(ans1,ans2))
flag = ;
}
if(flag==) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
else if(len == ){
int k = a[]-a[];
int b = a[] - k*;
int flag = ;
for(i=;i<=m;i++){
if(i*k+b!=a[i]){
flag = ;break;}
}
if(flag == )
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
else if(len==){
sort(b+,b+);
//cout<<b[1]<<endl<<b[2]<<endl<<b[3]<<endl;
if(b[]==*b[]+b[]||b[]==*b[]+b[]||b[]*==b[]+b[])
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
else
cout<<"No"<<endl;
return ;
}
Codeforces Round #431 (Div. 2) B. Tell Your World的更多相关文章
- Codeforces Round #431 (Div. 1)
A. From Y to Y time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #431 (Div. 2) C. From Y to Y
题目: C. From Y to Y time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #431 (Div. 2)
A. Odds and Ends Where do odds begin, and where do they end? Where does hope emerge, and will they e ...
- Codeforces Round #431 (Div. 2) C
From beginning till end, this message has been waiting to be conveyed. For a given unordered multise ...
- 【Codeforces Round #431 (Div. 1) D.Shake It!】
·最小割和组合数放在了一起,产生了这道题目. 英文题,述大意: 一张初始化为仅有一个起点0,一个终点1和一条边的图.输入n,m表示n次操作(1<=n,m<=50),每次操作是任选一 ...
- 【Codeforces Round 431 (Div. 2) A B C D E五个题】
先给出比赛地址啦,感觉这场比赛思维考察非常灵活而美妙. A. Odds and Ends ·述大意: 输入n(n<=100)表示长度为n的序列,接下来输入这个序列.询问是否可以将序列划 ...
- 【推导】【分类讨论】Codeforces Round #431 (Div. 1) B. Rooter's Song
给你一个这样的图,那些点是舞者,他们每个人会在原地待ti时间之后,以每秒1m的速度向前移动,到边界以后停止.只不过有时候会碰撞,碰撞之后的转向是这样哒: 让你输出每个人的停止位置坐标. ①将x轴上初始 ...
- 【推导】【贪心】Codeforces Round #431 (Div. 1) A. From Y to Y
题意:让你构造一个只包含小写字母的可重集,每次可以取两个元素,将它们合并,合并的代价是这两个元素各自的从‘a’到‘z’出现的次数之积的和. 给你K,你构造的可重集必须满足将所有元素合而为一以后,所消耗 ...
- Codeforces Round #431 (Div. 2) B
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a c ...
随机推荐
- I2S音频总线学习
IIS音频总线学习(一)数字音频技术 一.声音的基本概念 声音是通过一定介质传播的连续的波. 图1 声波 重要指标: 振幅:音量的大小 周期:重复出现的时间间隔 频率:指信号每秒钟变化的次数 声音按频 ...
- Luogu4139 上帝与集合的正确用法 拓展欧拉定理
传送门 题意:求$2^{2^{2^{2^{...}}}} \mod p$的值.$p \leq 10^7$ 最开始想到的是$x \equiv x^2 \mod p$,然后发现不会做... 我们可以想到拓 ...
- 在属性property做一些简单的验证
开发C#的程序,写到属性property时,我们可以在Set方法中做一些简单的规则验证: 如下面,Insus.NET写一个Age属性,只允许用户输入10以内的数字: class AA { privat ...
- OSC Source Code Innovation Salon(2018.10.20)
时间:2018.10.20地点:北京 朝阳 浦项中心B座2层
- WPF 带清除按钮的文字框SearchTextBox
原文:WPF 带清除按钮的文字框SearchTextBox 基于TextBox的带清除按钮的搜索框 样式部分: <!--带清除按钮文字框--> <Style TargetType=& ...
- 【转】分布式一致性算法:Raft 算法(Raft 论文翻译)
编者按:这篇文章来自简书的一个位博主Jeffbond,读了好几遍,翻译的质量比较高,原文链接:分布式一致性算法:Raft 算法(Raft 论文翻译),版权一切归原译者. 同时,第6部分的集群成员变更读 ...
- BootStrap学习(6)_模态框
一.模态框 模态框(Modal)是覆盖在父窗体上的子窗体.通常,目的是显示来自一个单独的源的内容,可以在不离开父窗体的情况下有一些互动.子窗体可提供信息.交互等. 如果只使用该功能,只引入BootSt ...
- Luogu P1337 [JSOI2004]平衡点 / 吊打XXX
一道入门模拟退火的经典题,还是很考验RP的 首先我们发现神TM这道题又和物理扯上了关系,其实是一道求广义费马点的题目 首先我们可以根据物理知识得到,当系统处于平衡状态时,系统的总能量最小 又此时系统的 ...
- java基础(个人学习笔记) A
1. 声明long类型的变量 需要在数值的末尾+l/L.(不加L的话,貌似默认就是int型了.当给long赋值一个超过int范围的值的时候,会出问题.) 2. package java_ ...
- Linux 磁盘与磁盘分区
Linux 系统中所有的硬件设备都是通过文件的方式来表现和使用的,我们将这些文件称为设备文件,硬盘对应的设备文件一般被称为块设备文件.本文介绍磁盘设备在 Linux 系统中的表示方法以及如何创建磁盘分 ...