BZOJ1610: [Usaco2008 Feb]Line连线游戏

2022-12-24,,,,

1610: [Usaco2008 Feb]Line连线游戏

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 1301  Solved: 571
[Submit][Status]

Description

Farmer John最近发明了一个游戏,来考验自命不凡的贝茜。游戏开始的时 候,FJ会给贝茜一块画着N (2 <= N <= 200)个不重合的点的木板,其中第i个点 的横、纵坐标分别为X_i和Y_i (-1,000 <= X_i <=1,000; -1,000 <= Y_i <= 1,000)。 贝茜可以选两个点画一条过它们的直线,当且仅当平面上不存在与画出直线 平行的直线。游戏结束时贝茜的得分,就是她画出的直线的总条数。为了在游戏 中胜出,贝茜找到了你,希望你帮她计算一下最大可能得分。

Input

* 第1行: 输入1个正整数:N

* 第2..N+1行: 第i+1行用2个用空格隔开的整数X_i、Y_i,描述了点i的坐标

Output

第1行: 输出1个整数,表示贝茜的最大得分,即她能画出的互不平行的直线数

Sample Input

4
-1 1
-2 0
0 0
1 1

Sample Output

* 第1行: 输出1个整数,表示贝茜的最大得分,即她能画出的互不平行的直线数

HINT

4 输出说明: 贝茜能画出以下4种斜率的直线:-1,0,1/3以及1。

Source

Silver

题解:
早上起来又水了一发。。。
枚举所有可能的二元组,把它们的斜率放进数组,拍个序,扫一遍找答案即可
代码:

 const eps=1e-7;
var n,i,j,tot,ans:longint;
a:array[..] of double;
x,y:array[..] of longint;
function cmp(x,y:double):boolean;
begin
if abs(x-y)<eps then exit(false);
if x<y then exit(true) else exit(false);
end; procedure sort(l,r:longint);
var i,j:longint;x,y:double;
begin
i:=l;j:=r;x:=a[(i+j)>>];
repeat
while cmp(a[i],x) do inc(i);
while cmp(x,a[j]) do dec(j);
if i<=j then
begin
y:=a[i];a[i]:=a[j];a[j]:=y;
inc(i);dec(j);
end;
until i>j;
if i<r then sort(i,r);
if j>l then sort(l,j);
end;
begin
assign(input,'input.txt');assign(output,'output.txt');
reset(input);rewrite(output);
readln(n);tot:=;
for i:= to n do readln(x[i],y[i]);
for i:= to n- do
for j:=i+ to n do
begin
inc(tot);
if x[j]-x[i]<> then a[tot]:=(y[j]-y[i])/(x[j]-x[i])
else a[tot]:=maxlongint;
end;
sort(,tot);
for i:= to tot do
if (i=) or (cmp(a[i-],a[i])) then inc(ans);
writeln(ans);
close(input);close(output);
end.

BZOJ1610: [Usaco2008 Feb]Line连线游戏的相关教程结束。

《BZOJ1610: [Usaco2008 Feb]Line连线游戏.doc》

下载本文的Word格式文档,以方便收藏与打印。