Codeforces--849B--Tell Your World

题目描述:
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
5
-1 -2 0 0 -5
5
5 4 3 2 1
5
1000000000 0 0 0 0
输出:
Yes
No
No
Yes
题意:
给你一堆点,问这些点能不能组成两条平行线,使这两条平行线不重合,而且每条边至少有一个点。
题解
拿前三个点出来算斜率就好了
代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;

const int maxn = 1000 + 5;
int a[maxn];
int n;

bool cal(double x){
    set<double>s;
    for(int i = 1; i <= n; i ++){
        double k = (1.0) * a[i] - i * x;
        s.insert(k);
    }
    if(s.size() == 2) return true;
    else return false;
}

int main(){
    while(scanf("%d",&n)!=EOF){
        for(int i = 1; i <= n; i ++) scanf("%d",&a[i]);
        double k1 = double(a[3] - a[1]) / (2.0);
        double k2 = double(a[2] - a[1]) / (1.0);
        double k3 = double(a[3] - a[2]) / (1.0);
        if(cal(k1) || cal(k2) || cal(k3)){
            printf("Yes\n");
        }
        else printf("No\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值