Count the Stars

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.