兩條平行線覆蓋所有點

2021-08-07 16:23:38 字數 2789 閱讀 9982

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).

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 y

1, y

2, ..., y

n (- 109 ≤ y

i ≤ 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 points1, 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.

題意 : 依次給出 y1 y2 y3 ... yn,表示點得縱座標,每個點的橫座標就是對應的下標

(1,y1) (2,y2)...(n,yn) 問你這些點能不能被兩條平行的直線貫穿,即所有點都在這兩條直線上,且這兩條直線不能平行

思路:對於大問題,先縮小為小問題

首先,只有兩個點的時候,隨意都可以把它畫成兩條平行的線,然後是三個點,那麼其中一條線要穿過兩個點,然後第三個點所在的直線也必須與前一條直線平行,那麼我們就可以找出三種方案,就是兩兩點組合確定好一條直線。

在畫了三個點的情況之後,增加乙個點,但是我們只能判斷這個點是否在前面的兩條直線上,也就是說,前面的三個點就已經確定了線的斜率。

也就是說,利用前面三個點得到的三個斜率,必定有乙個是正確的,那麼我們就只需要列舉那三個斜率,然後判斷是否所有點分布在兩條為該斜率且不平行的線上就可以了

我列舉斜率之後,對於每個點,計算出過改點且為該斜率情況下的直線經過y軸的點的縱座標是多少,然後記錄一下又多少個不同的過y軸縱座標,只有當數目為2的時候才正確。

#include

#include

#include

#include

using

namespace

std;  

map,int

>m;  

intop[1005];  

double

ang[5];  

intmain()  

ang[1] = (op[2] - op[1]) * 1.0 / (2 - 1);  

ang[2] = (op[3] - op[2]) * 1.0 / (3 - 2);  

ang[3] = (op[3] - op[1]) * 1.0 / (3 - 1);  

flag = 0;  

for(

inta = 1;a <= 3;a++)else

}  if

(cnt == 2)  

}  if

(flag)  

puts("yes"

);  

else

puts("no"

);  

}  return

0;  

}  

愛的平行線

無可奈何,去了s校。後來在百般壓力之下,13年的時候在w班留了下來,讓是沒想到的是隨機卻只是 偽隨機 甚至連 偽隨機 都說不上。後來遇到了不該遇到的人,或者說是我找到了她吧,又或者說是你總能找到乙個吧。小y在我看來的確可以說是很美麗,可是乙個人的品行在我面前更為清晰,男孩的強調讓人很是懷念,其所處環...

數學基礎 第五章 相交線與平行線

5.1相交線 5.1.1相交線 1和 2有一條公共邊0c,它們的另 邊互為反向延長線 1 和 2互補 具有這種關係的兩個 角,互為鄰補角 adjacent angles on a stright line 1和 3有乙個公共頂點o,並且 1的兩邊分別是 3的兩邊的反向延長線,具有這種位置關 系的兩個...

計算判斷兩條線是否垂直,平行,相交,求相交點座標

平行線的k斜率相等 l1 y kx b l2 y kx c 即 k1 1 k2.或 k1 k2 1.a為跟隨移動的點,c為固定點,move為移動點,求過一點d與直線垂直的交點?ps y kx b 已知兩點求ac bc所在直線方程 y x k b2 直線垂線方程let k1 a.y c.y a.x c...