StarsTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 6479 Accepted Submission (s): 2570
Problem descriptionastronomers often examine star maps where stars is represented by points on a plane and All star has Cartesian coordinates. The level of a star is a amount of the stars that is not higher and is not the right of the given star. Astronomers want to know the distribution of the levels of the stars.
For example, look at the map shown on the above. Level of the star number 5 are equal to 3 (it's formed by three stars with a numbers 1, 2 and 4). And the levels of the stars numbered by 2 and 4 is 1. At this map there is only one star of the level 0, and the level 1, one star of the level 2, and one star of the Level 3.
You is to write a program, that would count the amounts of the stars of each level on a given map.
Inputthe first line of the input file contains a number of stars N (1<=n<=15000). The following N lines describe coordinates of stars (both integers X and Y per line separated by a space, 0<=x,y<=320 ). There can be is only one star at a point of the the plane. Stars is listed in ascending order of Y coordinate. Stars with equal Y coordinates is listed in ascending order of X coordinate.
Outputthe output should contain N lines, one number per line. The first line contains amount's stars of the level 0, the second does amount of stars of the level 1 and so on, the last Line contains amount of stars of the level N-1.
Sample Input
51 15 17 13 35 5
Sample Output
12110
Source
Ural Collegiate Programming Contest 1999
Click to open link
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < Stdlib.h> #define N 32001using namespace Std;int n;int c[n];int num[n];int lowbit (int x) { return x& (-X);} int getsum (int x) { int s = 0; while (x>0) { s + = c[x]; X-= Lowbit (x); } return s;} void build (int x,int y) { while (x<=n) { c[x] + = y; x + = Lowbit (x); }} int main () { while (scanf ("%d", &n)!=eof) { memset (num,0,sizeof (num)); Memset (C,0,sizeof (c)); int x, y; for (int i=0; i<n; i++) { scanf ("%d%d", &x,&y); Num[getsum (x+1)]++; Build (x+1,1); } for (int i=0; i<n; i++) { printf ("%d\n", Num[i]); } } return 0;}
Copyright NOTICE: This article is the original blogger article, if you have special needs, please contact Bo Master qq:793977586.
HDU 1541 Stars (tree-like array)