zoukankan      html  css  js  c++  java
  • POJ 2352 Stars

    POJ 2352 Stars

    Description

    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.
    img
    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
    

    Hint

    This problem has huge input data,use scanf() instead of cin to read data to avoid time limit exceed.

    题目翻译:(by fsw)

    整个天空建立一个平面直角坐标系,每颗星星都有一个坐标,横纵坐标都小于等于这个坐标的星星数量为这颗星星的等级。

    问所有星星的等级。

    题解:

    事实证明,这道题完全等于弱弱的战壕我弱弱的战壕的博客连测试数据都一点没动,但是不能直接拿弱弱的战壕交,因为弱弱的战壕会TLE(判重操作浪费大量时间),所以改进了一份代码。

    (想看详细讲解请移步弱弱的战壕博客(链接在上))

    AC代码:

    #include<cstdio>
    using namespace std;
    const int maxn=32005;
    int c[maxn],ans[maxn],n,x,y;
    void fix(int x)
    {
    	for(int i=x;i<=maxn;i+=i&-i)
            c[i]++;
    }
    int getsum(int x)
    {
    	int ret=0;
    	for(int i=x;i;i-=i&-i)
            ret+=c[i];
    	return ret;
    }
    int main()
    {
    	scanf("%d",&n);
    	for(int i=1;i<=n;i++)
    	{
    		scanf("%d%d",&x,&y);
    		ans[getsum(++x)]++;
    		fix(x);
    	}
    	for(int i=0;i<n;i++)
    	    printf("%d
    ",ans[i]);	
    	return 0;
    }
    
  • 相关阅读:
    cocos2dx的发展的例子2048(加入动画版)
    Hibernate操作Clob数据类型
    json级联城市
    Ubuntu Linux 永山(mount)分
    C++出现计算机术语5
    Cocos2d-x 3.0 红孩儿私人义务教育
    大页(huge pages) 三大系列 ---计算大页配置参数
    EJB_消息驱动发展bean
    HDU5086Revenge of Segment Tree(数论)
    第五章_JSTL
  • 原文地址:https://www.cnblogs.com/fusiwei/p/11287136.html
Copyright © 2011-2022 走看看