POJ 2352Stars Test Instructions & Code (c + +)

Source: Internet
Author: User

Topic Links:
http://poj.org/problem?id=2352
Test instructions:
There are n stars in the coordinates, if a star coordinates (x, y ), its lower-left position is: (x0,y0), X0<=x and Y0<=y. If there is a star at the lower left, it means that the star belongs to level X, the
is incremented by y, and if y is the same, x increments the order of N stars, and the number of levels is calculated.
:
Because y is given in ascending order, the sum of the number of occurrences in the x-coordinate is the sum of the stars in the lower-left position of the second star.
Code:

 #include <iostream> #include <algorithm> #include <stdio.h> #include <
String.h> #define MAXN (15005) using namespace std;
int n,m,num[32005],vis[15005];
    int lowbit (int x) {return x& (-X);} void Add (int x) {for (int i=x;i<=32001;i+=lowbit (i)) num[i]+=1;    
return;
    } int query (int x) {int ans=0;
    for (int i=x;i>0;i-=lowbit (i)) ans+=num[i];
return ans;
    } int main () {scanf ("%d", &n);
        for (int i=1;i<=n;i++) {int x, y;
        scanf ("%d%d", &x,&y);        
        x + +;
        Add (x);
    Vis[query (x)]++;
    Cout<<query (x) << "<<vis[query (x)]<<endl;
} for (int i=1;i<=n;i++) printf ("%d\n", Vis[i]); }

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.