• Codeforces 849 B Tell your world 思维


      题目链接: http://codeforces.com/contest/849/problem/B

      题目描述: 给你n个坐标点, 问你能不能用两条平行的执行穿过所有的点

      解题思路: 三个基准线, k12, k13, k23, 有一条平行线一定在这三条之间, 这样我们只需要遍历所有的点看看是不是满足   和基准线共线的同时还只和另外一条唯一的直线共线即可 这一条件即可

      代码: 

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cstring>
    #include <iterator>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <deque>
    #include <map>
    #include <set>
    #define lson l, m, rt<<1
    #define rson m+1, r, rt<<1|1
    #define mem0(a) memset(a,0,sizeof(a))
    #define sca(x) scanf("%d",&x)
    #define de printf("=======
    ")
    typedef long long ll;
    using namespace std;
    
    const double eps = 1e-7;
    const int maxn = 1e3+10;
    int n;
    double a[maxn];
    
    int solve( double k ) {
        int flag = 0;
        int point = -1;
        for( int i = 2; i <= n; i++ ) {
            if( a[i] - a[1] == k * (i - 1) ) continue;
            flag = 1;
            if( point < 0 ) {
                point = i;
            }
            else if( a[i] - a[point] != k * (i - point) ) {
                flag = 0;
                break;
            }
        }
        if( flag == 1 ) return 1;
        else return 0;
    }
    
    int main() {
        sca(n);
        for( int i = 1; i <= n; i++ ) {
            scanf( "%lf", a+i );
        }
        double k1 = a[2]-a[1];
        double k2 = a[3]-a[2];
        double k3 = (a[3]-a[1])*0.5;
        if( solve(k1) || solve(k2) || solve(k3) ) {
            printf( "Yes
    " );
        }
        else {
            printf( "No
    " );
        }
        return 0;
    }
    View Code

      思考: 这场比赛真的是很绝望, 我不会, 说实话真的想不到, 我连A, B都做不出来, 和新手有啥区别.......打了一年了还是没想到......我一开始的思路也是斜率, 但是偏了, 想得去往两个....算了, 不说了, 以后熬夜打CF了, 不能再咸鱼了吧, 真的大三了

  • 相关阅读:
    03 http请求协议与响应协议
    02 web应用程序
    Django web框架目录
    01 http协议
    Django框架
    Bootstrap栅格系统
    bootstrap介绍和引入
    Python中日志logging模块
    Python 装饰器实现单列模式
    Python 如何理解可更改元组中的可变序列
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7467138.html
Copyright © 2020-2023  润新知