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 ...
随机推荐
- 源代码管理工具(下)-SVN目录结构
内容中包含 base64string 图片造成字符过多,拒绝显示
- Html页面雪花效果的实现
简单介绍 昨天修改了一下博客所用的模板,冬天来了,给自己的博客加点雪花,感觉更有意境. 百度找到了非常多的结果,最终还是选用了cfs.snow.js,很赞压缩之后只有1kb左右,而且不会影响页面使用, ...
- JVM规范系列第5章:加载、链接与初始化
加载是根据特定名称查找类或接口类型的二进制表示(Binary Representation),并由此二进制表示创建类或接口的过程. 加载,就是指去寻找类或接口的过程. 链接是为了让类或接口可以被 Ja ...
- Name方法
重命名磁盘文件.目录或文件夹. 语法 Name 旧路径名称 As 新路径名称 “Name”**** 语句语法包含以下部分: 部分 说明 旧路径名称 必需. 字符串表达式,指定现有的文件名和位置;可能包 ...
- 更换Ubuntu源为国内源的操作记录
我们都知道,Ubuntu的官方源对于国内用户来说是比较慢的,可以将它的源换成国内的源(比如阿里源),这样用起来就很快了.下面记录下更换操作: 首先了解下/etc/apt/sources.list文件 ...
- C++STL——优先队列
一.相关定义 优先队列容器与队列一样,只能从队尾插入元素,从队首删除元素.但是它有一个特性,就是队列中最大的元素总是位于队首,所以出队时,并非按照先进先出的原则进行,而是将当前队列中最大的元素出队.这 ...
- 归并排序O(nlogn)
先分治再合并 代码 #include<bits/stdc++.h> using namespace std; #define ll long long int a[1000],t[1000 ...
- Word frequency program ver.1
先吐槽一下自己 做这个作业的时候完全没有提前考虑好时间 导致要提交前一天晚上通宵写代码 而且还满满的bug TAT 缓一口气 程序还在继续写 先把有点累 想着先把博客写了 PART I 预计时间: 语 ...
- pair project elevator
结对编程——电梯调度 12061181 高孟烨 12061182 郝倩 1.结对编程的优缺点: 优点:结对编程可以结合两个人各自擅长之地,充分发挥两个人各自的优势,两个人一起合作效率会更高.一份工作两 ...
- 【CV】ICCV2015_Unsupervised Visual Representation Learning by Context Prediction
Unsupervised Visual Representation Learning by Context Prediction Note here: it's a learning note on ...