There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
4 0 0
1 1
2 2
2 0
-1 -1
2
2 1 2
1 1
1 0
1
Explanation to the first and second samples from the statement, respectively:
給定n個敵人的位置和槍的起始位置,一槍可以射殺經過槍位置直線上的所有敵人
問至少需要多少槍可以殺光所有敵人
數學題,用斜率或者叉積都可以求解
我用的是斜率,將槍的位置看成原點,求所有敵人相對槍的坐標,則敵人i的斜率為yi/xi
枚舉每個活着敵人,將和該敵人相同斜率的人都殺光,子彈數+1
遍歷完后子彈數即為答案
#include <iostream>
using namespace std;
int main()
{
int n,x,y;
int use[1010];
double px[1010];
double py[1010];
cin>>n>>x>>y;
for(int i=1;i<=n;i++)
{
cin>>px[i]>>py[i];
px[i]-=x;
py[i]-=y;
}
int res=0;
bool flag=false;
for(int i=1;i<=n;i++)
{
if(px[i]==0)
{
use[i]=1;
if(!flag)
{
flag=true;
res++;
}
else
continue;
}
if(!use[i])
{
res++;
use[i]=1;
double k=py[i]/px[i];
for(int j=1;j<=n;j++)
{
if(py[j]/px[j]==k&&!use[j])
use[j]=1;
}
}
}
cout<<res<<endl;
return 0;
}