zoukankan      html  css  js  c++  java
  • 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. }
  • 相关阅读:
    SysUtils.UpperCase、SysUtils.LowerCase 大小写转换
    Sql Server 2005 数据库备份还原后出现“受限制用户”问题的解决
    为什么要跪谢
    【基础】C#卸载快捷方式添加
    DataTable 复制 DataRow 出现 “该行已经属于另一个表”错误的解决办法
    将int型转化成五位字符串,前面用0填充
    C#嵌套类的使用方法及特性(转)
    net内存回收与Dispose﹐Close﹐Finalize方法(转)
    sqlhelper中文注释版(转)
    windows2003消息队列的安装
  • 原文地址:https://www.cnblogs.com/767355675hutaishi/p/3683403.html
Copyright © 2011-2022 走看看