Number of stars time limit: 1 Sec Memory Limit: MB
Submit: 7 Solved: 3
[Submit] [Status] [Web Board] Description
One day, Xiao Ming sat in the yard to count the stars, Gardon a problem to her: Gardon in the sky drew a rectangular area, let him enter the rectangular area of how many stars, the Merciful God also for him to mark the coordinates of each star. But Xiaoming counted on the eyes, but his principle is: would rather most once, must not miss one. If Xiaoming tells you the coordinates of the stars he has counted, can you help him with the handling of the rows (if the coordinates of the two stars are the same, it is considered a star) and the number of stars is calculated.
Input
First enter an integer n (n<=300), the next n pairs of integers, each pair represents the position of one of the stars that Xiaoming counted (the coordinates of the stars are between 10000 and 10000).
Output
The number of stars to output.
Sample Input
50 31 51 10 11 5
Sample Output
4
#include <iostream> #include <stdio.h> #include <algorithm>using namespace std;struct point{ int x; int y;}; int CMP (point A,point b) { if (a.x!=b.x) return a.x<b.x; else return a.y<b.y;} int main () { int n,i,count; Point a[400]; while (scanf ("%d", &n)!=eof) { count=0; for (i=0;i<n;i++) { cin>>a[i].x>>a[i].y; } Sort (a,a+n,cmp); for (i=0;i<n;i++) {while (i<n-1 && a[i].x==a[i+1].x &&a[i].y==a[i+1].y)//AAABBC { i++; } count++; } cout<<count<<endl; } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Count the Stars