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的范围) 这个题目主要是卡时间的,一定要有好的算法。