“玲珑杯”ACM比赛 Round #4 G -- See car

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(109a,b109,0n105)a,b,n(−109≤a,b≤109,0≤n≤105).next nn lines, each line contains two integer (xi,yi)(109xi,yi109)(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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值