StarsTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 5378 Accepted Submission (s): 2125
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
Remember to do this before the right time, will not do, just keep not do. Now, I've got this problem. Immediately feel the past of their own good food. Part entered: Stars is listed in ascending order of Y coordinate. Stars with equal Y coordinates is listed in ascending order of X coordinate. People have already helped to arrange the order. I've never done it before. Code:
#include <cstdio> #include <cstring> #define MAX 20000#define LEN 32500using namespace std; struct Point{int x, Y;} P[max]; int T[len], level[max]; int lowbit (int n) {return n& (-n);} void Update (int pos) {if (pos = = 0) return, while (Pos<len) {t[pos]++;p os + = Lowbit (pos);}} int sum (int pos) {int s = 0; while (pos>0) {s + = T[pos];p os-= Lowbit (POS);} return s;} int main () {int n, while (~scanf ("%d", &n)) {memset (level,0, (n+10) *sizeof (int)), memset (t,0,sizeof (t)), and for (int i = 0; I < n; ++i) {scanf ("%d%d", &p[i].x, &p[i].y);p [i].x++;} for (int i = 0; i < n; ++i) {level[sum (p[i].x)]++; update (p[i].x);} for (int i = 0; i < n; ++i) {printf ("%d\n", Level[i]);}} return 0;}
with June
hdu1541 Stars tree-like array water problem