zoukankan      html  css  js  c++  java
  • Codeforces Round #431 (Div. 2) B. Tell Your World

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

    思路:

    懒得写了,暴力枚举各种情况讨论。

    代码很丑,之前有两个特殊情况没判到,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[1009],b[1009];
        cin>>m;
        for(i=1;i<=m;i++)
            cin>>a[i];
            b[0] = -99999999;
            int len = 1;
        for(i=2;i<=m;i++){
            ll ans = a[i]-a[i-1];
            //cout<<ans<<endl;
            cnt = 0;
            for(j=0;j<len;j++)
                if(ans!=b[j])
                cnt++;
            if(cnt == len){
                b[len] = ans;len++;
              }
            }
            len--;
            //cout<<len<<endl;
            if(len == 2){
                 for(i=2;i<=m;i++){
                 ll ans = a[i]-a[i-1];
                 mp[ans]++;
                 }
                 if(mp[b[1]]==1||mp[b[2]]==1)
                    cout<<"Yes"<<endl;
                 else{
                    int flag = 0;
                    for(i=2;i<m;i++){
                        ll ans1 = a[i] - a[i-1];
                        ll ans2 = a[i+1] - a[i];
                        if(ans1+ans2>max(ans1,ans2))
                            flag = 1;
                    }
                    if(flag==0) cout<<"Yes"<<endl;
                    else  cout<<"No"<<endl;
                 }
            }
            else if(len == 1){
                int k = a[2]-a[1];
                int b = a[1] - k*1;
                int flag = 0;
                for(i=1;i<=m;i++){
                    if(i*k+b!=a[i]){
                        flag = 1;break;}
                }
                if(flag == 1)
                    cout<<"Yes"<<endl;
                else
                    cout<<"No"<<endl;
            }
            else if(len==3){
                sort(b+1,b+4);
                //cout<<b[1]<<endl<<b[2]<<endl<<b[3]<<endl;
                if(b[3]==2*b[1]+b[2]||b[3]==2*b[2]+b[1]||b[2]*2==b[1]+b[3])
                    cout<<"Yes"<<endl;
                else
                    cout<<"No"<<endl;
            }
            else
                cout<<"No"<<endl;
        return 0;
    }
  • 相关阅读:
    text-overflow white-space word-break word-wrap word-spacing line-clamp 傻傻分不清楚0.0=>文本超出显示省略号/数字英文字母折行有关css 属性/显示两行,第二行省略号显示css方法
    jq 操作表单中 checkbox 全选 单选
    用 pdf.js兼容部分安卓显示PDF在线预览 时,a标签直接链接参数文件不能含中文的解决办法
    通过form实现enter事件
    小白随笔之数组的方法
    引用类型之Array
    Reset
    js常用事件
    让女朋友能懂的网络技术篇之动态代理
    图论之Dijkstra算法
  • 原文地址:https://www.cnblogs.com/kls123/p/7465423.html
Copyright © 2011-2022 走看看