#include  <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n, y[maxn];
struct Point {
    int x, y;
    Point() {}
    Point(int x, int y) {
        this->x = x;
        this->y = y;
    }
};
vector<double> check;
map<double, int> cnt, num;
int main() {
    check.clear();
    cnt.clear();
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &y[i]);
    }
    for(int i = 1; i <= n; i++) {
        int a = (i + 1) % n;
        int b = (i + 2) % n;
        bool tag = true;
        for(int j = 1; j <= n; j++) {
            if(j != i) {
                int tx = j, ty = y[j];
                if((y[a] - y[b]) * tx + (b - a) * ty + a * y[b] - b * y[a] != 0) {
                    tag = false;
                    break;
                }
            }
        }
        if((y[a] - y[b]) * i + (b - a) * y[i] + a * y[b] - b * y[a] == 0) {
            tag = false;
        }
        if(tag) {
            printf("Yes\n");
            return 0;
        }
    }
    for(int i = 1; i <= n - 1; i++) {
        for(int j = i + 1; j <= n; j++) {
            double k = (double)(y[j] - y[i]) / (double)(j - i);
            cnt[k]++;
            if(cnt[k] == 2) {
                check.push_back(k);
            }
        }
    }
    for(int i = 0; i < check.size(); i++) {
        num.clear();
        double k = check[i];
        int sum = 0;
        for(int j = 1; j <= n; j++) {
            double tb = (double)y[j] - k * (double)j;
            num[tb]++;
            if(num[tb] == 1) {
                sum++;
                if(sum > 2) {
                    break;
                }
            }
        }
        if(sum == 2) {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");    
    return 0;
}

面前几乎天开始看Uncle Bob的《Clean
Code》,在率先章里,作者讨论了这般的一个问题:什么样的code才是Clean
code。对于这个题材,一千只Programmer可能会时有发生一千只答案,所以作者请教了6独响当当的学者,问问他们对此这题目的意见,以下三单是自认为未那么虚的,比较起操作参考意义之报:

问题大意:给定N个点,问是否是个别条平行且无重叠的直线让所有点分别获于少长达直线上。

3. Ron Jeffries 《Extreme Programming Installed》 《Extreme Programming Adventures in C#》的作者

In recent years I begin, and nearly end, with Beck’s rules of simple
code. In priority order, simple code:
• Runs all the tests;
• Contains no duplication;
• Expresses all the design ideas that are in the system;
• Minimizes the number of entities such as classes, methods,
functions, and the like.
… Of these, I focus mostly on duplication. When the same thing is
done over and over, it’s a sign that there is an idea in our mind that
is not well represented in the code. I try to figure out what it is.
Then I try to express that idea more clearly.
Expressiveness to me includes meaningful names, and I am likely to
change the names of things several times before I settle in…. I also
look at whether an object or method is doing more than one thing. If
it’s an object, it probably needs to be broken into two or more
objects. If it’s a method, I will always use the Extract Method
refactoring on it, resulting in one method that says more clearly what
it does, and some submethods saying how it is done…

于这边,Ron Jeffries甚至将test放在第一员。
有关作者的最后一久:Minimizes the number of entities such as classes,
methods, functions, and the
like。我觉得作者应是来前提的。不然的话,如果坐充分也业内,那么富有的代码都放一个近似,一个方法中好了,这样显然是雅的。而且撰稿人后面自己吗干,会拿一个大的类分成两单稍之,会用extract
method来分解一个杀丰富的点子。总体来说,应该大多数人口且见面确认:几单稍的类比一个坏之类似设好,几只小的方比较一个异常之法而好。

下3单应答相对来说就比较虚了,大家省就算好。

input

4. Grady Booch, 《Object Oriented Analysis and Design with Applications》作者

Clean code is simple and direct. Clean code reads like well-written
prose. Clean code never obscures the designer’s intent but rather is
full of crisp abstractions and straightforward lines of control.

概括直接,如诗一般, straightforward lines of
control,说了齐没说。abstraction,相对来说还是于实际的。

You
can print each letter in any case (upper or lower).

5. Michael Feathers, 《Working Effectively with Legacy Code》作者

I could list all of the qualities that I notice in clean code, but
there is one overarching quality that leads to all of them. Clean code
always looks like it was written by someone who cares. There is
nothing obvious that you can do to make it better. All of those things
were thought about by the code’s author, and if you try to imagine
improvements, you’re led back to where you are, sitting in
appreciation of the code someone left for you—code left by some- one
who cares deeply about the craft.

这边的关键是Care。但是如何的代码是被author
care过得啊?这里没有强烈的指标可以依据,只能凭借我们团结一心去看清。

Input

2. Dave Thomas, 出版公司The Pragmatic Bookshelf Co-founder,《Pragmatic Programmer》(中文叫程序员修炼之志)、《Programming Ruby》作者。

Clean code can be read, and enhanced by a developer other than its
original author. It has unit and acceptance tests. It has meaningful
names. It provides one way rather than many ways for doing one thing.
It has minimal dependencies, which are explicitly defined, and pro-
vides a clear and minimal API. Code should be literate since depending
on the language, not all necessary information can be expressed
clearly in code alone.

此间的几单重要是:

  • Can be read and enhanced by others
  • Unit and acceptance tests
  • Meaningful names
  • Minimal dependency, minimal API

此的test和Minimal API是咱们相应注意的事物,

 

6. Ward Cunningham, Wiki发明人,Fit发明人,eXtreme Programming共同发明人. Design Patterns、OO思想领袖。The godfather of all those who care about code.

You know you are working on clean code when each routine you read
turns out to be pretty much what you expected. You can call it
beautiful code when the code also makes it look like the language was
made for the problem.

“Pretty much what you
expected”,但是每个人expect的代码的典范都是免等同的,一个初家expected的代码的范可能相对也会见较初级,难道好也克如作clean
code吗?I might have a different opinion.

总一下,我个人觉得以下几点,非常值得我们参考:

  1. Single Responsibility. 一个类似才开其该做的工作,一个措施做同宗事。
  2. Minimal
    API:一个近似对外暴露的接口应该是不择手段少之,其实就也便代表多为此Composition,少用持续,因为累,意味着这近乎继承了父类所有的接口,这同Minimal
    API明显是相对的。
  3. Unit
    Test:这不是如出一辙起无关紧要的政工,不要说“仅仅是为测试”这样的话。。。
  4. Naming:这为是一样起十分重大之事体,类名,方法名,变量名等等,这还是十分影响可读性的。哪怕写起不大顺手,也欲以还好之可读性,设计一个重好的接口。为什么?因为读代码的年华较写代码的流年差不多发生10倍增不止,这个当书中也发关系,是透过人们对Emacs的施用状况,真实统计出来的。从另外一个角度来讲,代码写出来是一次性的,而自此为阅读的次数可是心有余而力不足估量的。
  5. DRY: Duplication is the root of all evil in software
    design.

世家觉得,什么样的代码才是好代码呢?

Output
“Yes” (without quotes) if it’s possible
to fulfill the requirements, and “No”
otherwise.

1. Bjarne Stroustrup, C++之父

I like my code to be elegant and efficient. The logic should be
straightforward to make it hard for bugs to hide, the dependencies
minimal to ease maintenance, error handling complete according to an
articulated strategy, and per- formance close to optimal so as not to
tempt people to make the code messy with unprinci- pled optimizations.
Clean code does one thing well.

这里的几乎单关键是:

  • Elegant:意味着你的代码看起老畅快
  • Efficient:这个可能同Bjarne
    Stroustrup的小圈子有关,毕竟使用C++的地方大多是对准效率要求老高之园地。
  • Error handling complete:完备的错误处理机制,这意味关注细节。
  • Does one thing well:就是咱们所说之,Single Responsibility!

input

No

 

B.
Tell Your World

5
5 4 3 2 1
5
-1 -2 0 0 -5

output

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.

Examples

Yes

 

The
first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number
of points.

 
检查斜率时,取出每一个如此的斜率然后带所有的点,统计截距的个数,如果当2,那么满足条件,否则不满足。

5
1000000000 0 0 0 0

output

 

input

The
second line contains n space-separated
integers y1, y2, …, yn ( - 109 ≤ yi ≤ 109) — the vertical
coordinates of each
point.

There
are n points on a coordinate plane, the i-th of which being (i, yi).

Yes

题目:

5
7 5 8 6 9

input

Connect
the countless points with lines, till we reach the faraway
yonder.

Output

output

No

代码:

output

分析:首先这个题目分为两种情形,一栽是一模一样漫漫直线有一个接触,另一样条直线覆盖了别样所有点;另一样栽情况是各条直线至少覆盖两个点。对于第一栽状态,我们要枚举每一个触及,然后于剩余的触及中任取两独点,然后判断是否满足条件;对于第二种植状况,我们首先不重的枚举任意两接触组成直线的斜率,再运一个map对斜率进行计数。最终我们以现出次数超过等于两破的斜率进行检查。