• star


    Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to 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 figure above. Level of the star number 5 is 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 are 1. At this map there are only one star of the level 0, two stars of the level 1, one star of the level 2, and one star of the level 3. 

    You are to write a program that will count the amounts of the stars of each level on a given map.
     

    Input

    The first line of the input file contains a number of stars N (1<=N<=15000). The following N lines describe coordinates of stars (two integers X and Y per line separated by a space, 0<=X,Y<=32000). There can be only one star at one point of the plane. Stars are listed in ascending order of Y coordinate. Stars with equal Y coordinates are listed in ascending order of X coordinate. 
     

    Output

    The output should contain N lines, one number per line. The first line contains amount of 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

    5
    1 1
    5 1
    7 1
    3 3
    5 5
     

    Sample Output

    1
    2
    1
    1
    0
    1. #include"stdio.h"
    2. #include"string.h"
    3. int c[32005];
    4. int a[32005];
    5. int n;
    6. int lowbit(int x)
    7. {
    8.     return x&(-x);
    9. }
    10. void updata(int x,int d)
    11. {
    12.     while(x<=32005)
    13.     {
    14.         c[x]+=d;
    15.         x+=lowbit(x);
    16.     }
    17. }
    18. long long int getsum(int x)
    19. {
    20.     long long int res=0;
    21.     while(x>0)
    22.     {
    23.         res+=c[x];
    24.         x-=lowbit(x);
    25.     }
    26.     return res;
    27. }
    28. int main()
    29. {
    30.     int i,x,y;
    31.     scanf("%d",&n);
    32.     memset(c,0,sizeof(c));
    33.     memset(a,0,sizeof(a));
    34.     for(i=1;i<=n;i++)
    35.     {
    36.         scanf("%d%d",&x,&y);
    37.         x++;//0<=x,y<=
    38.         a[getsum(x)]++;//点已经排好序,记录在X前面的星星 记录同等级的级数
    39.         updata(x,1);//记录个数,只要X<=当前点的横坐标
    40.     }
    41.     for(i=0;i<n;i++)
    42.     printf("%d ",a[i]);
    43. }
  • 相关阅读:
    你以为在用SharePoint但事实上不是
    python 站点爬虫 下载在线盗墓笔记小说到本地的脚本
    CF 552C 进制转换
    ArcGIS制图——多图层道路压盖处理
    数据结构实验图论一:基于邻接矩阵的广度优先搜索遍历
    ANTLR4权威參考手冊(一)
    Codeforces Round #270--B. Design Tutorial: Learn from Life
    二叉树近期公共父节点
    for循环遍历字符串的还有一种方法
    Android学习笔记技巧之垂直和水平滚动视图
  • 原文地址:https://www.cnblogs.com/767355675hutaishi/p/3683403.html
Copyright © 2020-2023  润新知