map的妙用

Description 

Staginner , the boss of A0A(Avoid 0 AC) Company, gives you a simple task, that is to calculate how many different points are there in the group of N points.

Input 

There are several test cases. 
The first line of each case contains a integer N(1<=N<=10^5), indicates that there are N points in the group. Then there will be N lines, and each line contains two integers x(0<=x<1000), y(0<=y<1000), indicates the coordinates of the point.

Output 

For each test case, you need only print one integer indicates the number of different points in this group.

Sample Input 


3
1 2
2 1
1 2

1
0 0

Sample Output 


2
1
#include <iostream>
#include <map>
using namespace std;

int main()
{
	map<int,int> m;
	int n;
	int x,y;
	while (scanf("%d",&n)!=EOF)
	{
		while(n--)
		{
			scanf("%d%d",&x,&y);
			m[x*10000+y]=1;
		}
		printf("%d\n",m.size());
		m.clear();
	}
	return 0;
}

map是通过不同的键值进行计数的,本题刚好用到map的性质,来将不同的点很好的区分开了。(注意x,y的范围)  这个题目主要是卡时间的,一定要有好的算法。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值