Codeforces Round #291 (Div. 2)---B. Han Solo and Lazer Gun



  
  
  
  
B. Han Solo and Lazer Gun
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The first line contains three integers nx0 и 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 xiyi ( - 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.

Output

Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.

Sample test(s)
input
4 0 0
1 1
2 2
2 0
-1 -1
output
2
input
2 1 2
1 1
1 0
output
1
Note

Explanation to the first and second samples from the statement, respectively:

此方法并不是本人想到的,因为简单易懂分享一下,比网上大部分的简洁很多。代码是直接从CF上copy过来的,题意是你在一个点上,周围是敌人,只要是在一条直线上的敌人都可以全部干掉,问最少需要打多少枪。这样我们就需要判断这些点是否在同一条直线上,这是候便自然想到了向量,可是在使用容器vector貌似比较麻烦,所以直接根据高中的知识两个向量平行充要条件是x1*y2-x2*y1=0;(顺便吐槽一句数学不好的人一辈子都要被碾压啊)
#include <iostream>
using namespace std;

int main()
{
	int num=0;
	int n,x0,y0;
	int map[1000][2];
	scanf("%d%d%d",&n,&x0,&y0);
	for(int i=0;i<n;i++)
	{
		int k=1;
		int x,y;
		scanf("%d%d",&x,&y);
		x-=x0;
		y-=y0;
		map[i][0]=x;
		map[i][1]=y;
		for(int j=0;j<i;j++)
		{
			if(map[i][0]*map[j][1]==map[i][1]*map[j][0])//判断是否是平行向量
			{
				k=0;
				break;
			}
		}
		if(k==1)
			num++;
	}
	printf("%d\n",num);
	return 0;
}

你可能感兴趣的:(Codeforces Round #291 (Div. 2)---B. Han Solo and Lazer Gun)