G -- See car
Time Limit:2s Memory Limit:64MByt
DESCRIPTION
You are the god of cars, standing at (a, b) point.There are some cars at point (xi,yi)(xi,yi). If lots of cars and you are in one line, you can only see the car that is nearest to yourself. How many cars can you see?
It is guaranteed that xi>axi>a and yi>byi>b.
INPUT
There are multiple test cases.The first line is a number T (T
≤11 ≤11), which means the number of cases.For each case, first line has three integers
a,b,n(−109≤a,b≤109,0≤n≤105)a,b,n(−109≤a,b≤109,0≤n≤105).next
nn lines, each line contains two integer
(xi,yi)(−109≤xi,yi≤109)(xi,yi)(−109≤xi,yi≤109), which means the position of car.
OUTPUT
one line --- the number of car that you can see.
SAMPLE INPUT
2
0 0 3
1 1
2 2
3 3
0 0 4
1 1
2 2
2 3
4 6
SAMPLE OUTPUT
1
2
题意:给出自己的所在点,再给出其他车的所在坐标,问你从自己所在位置最多能看到多少辆车,每一个方向只能看到这个方向的第一辆车
#include<cstdio>
#include<cstring>
#include<set>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1e5 + 10;
set<double> s;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int a,b,q;
int count = 0;
s.clear();
scanf("%d%d%d",&a,&b,&q);
while(q--)
{
int x,y;
scanf("%d%d",&x,&y);
double d = (double)(y - b) / (double)(x - a); // 求斜率,用斜率表示方向
if(s.find(d) != s.end())
continue;
else
{
s.insert(d);
count++;
}
}
printf("%d\n",count);
}
return 0;
}