Stars

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3680    Accepted Submission(s): 1449

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

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
 
Source
 
Recommend
LL
 

树状数组:

对于这样的数据结构,有特定的函数,可用.....至于其中的具体原因,也非三言两语能见真相于天下....,推荐去看数据结构相关书籍...

树状数组开始有lowbit()-----》这个函数与数字的字节有关,.....,看书

代码模式很简单为:

     int lowbit(int x)
{
return x&(-x) //-x其实是~X+1的结果....
}

然后就是一个add()
代码模式为:

    void  add(int pos , int d )
{
while(pos<maxn) //为po【】数组的边界
{
po[pos]+=d; //d为所要加的数值
pos+=lowbit(pos); //pos 为数组指针....
}
}

最后为求和:

sum();

代码模式:

    int  sum(int  x)
{
int ans ;
while(x>)
{
ans+=po[x];
x-=lowbit(x);
}
}

树状数组的最普遍的用途是用来快速求解一条线段a___b的和.....

所以面对问题,就要想尽办法将他转化到这种模式上来...这样就可以用这种方法来求解了啊...

代码如下::

 /*作者 : 龚细军,树状数组*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 35000
#include<cstdlib>
using namespace std; int po[maxn+],leve[maxn+]; int lowbit(int x)
{
return x&(-x);
} void add(int x)
{
while(x<maxn)
{
po[x]++;
x+=lowbit(x);
}
} int sum(int pos)
{
int ans=;
while(pos>)
{
ans+=po[pos];
pos-=lowbit(pos);
}
return ans;
} int main()
{
int n,y,i,x;
while(cin>>n)
{
memset(po,,sizeof(po));
memset(leve,,sizeof(int)*n);
for(i=;i<=n;i++)
{
/*y轴是升序的...所以不要予以考虑....*/
scanf("%d %d",&x,&y);
x++; /*右移一位,搓掉o,那样的话,就要经历无数次的lowbit(),调用,会超时*/
leve[sum(x)]++; /*放大避免x,轴有相同的数字*/
add(x);
}
for(i=;i<n;i++)
{
printf("%d\n",leve[i]);
}
}
return ;
}

HDUOJ-----1541 Stars的更多相关文章

  1. hdu 1541 Stars

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 思路:要求求出不同等级的星星的个数,开始怎么也想不到用树状数组,看完某些大神的博客之后才用树状数 ...

  2. POJ 2352 Stars(HDU 1541 Stars)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41521   Accepted: 18100 Descripti ...

  3. hdoj 1541 Stars【线段树单点更新+最大值维护】

    Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  4. HDU 1541 Stars (树状数组)

    Problem Description Astronomers often examine star maps where stars are represented by points on a p ...

  5. POJ 2352 &amp;&amp; HDU 1541 Stars (树状数组)

    一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~ ...

  6. HDU 1541 Stars (线段树)

     Problem Description Astronomers often examine star maps where stars are represented by points on ...

  7. HDU - 1541 Stars 【树状数组】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1541 题意 求每个等级的星星有多少个 当前这个星星的左下角 有多少个 星星 它的等级就是多少 和它同一 ...

  8. hdu 1541 Stars 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目意思:有 N 颗星星,每颗星星都有各自的等级.给出每颗星星的坐标(x, y),它的等级由所有 ...

  9. 题解报告:hdu 1541 Stars(经典BIT)

    Problem Description Astronomers often examine star maps where stars are represented by points on a p ...

  10. hdu 1541 Stars 统计<=x的数有几个

    Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

随机推荐

  1. 分布式消息系统Kafka初步(一) (赞)

    终于可以写kafka的文章了,Mina的相关文章我已经做了索引,在我的博客中置顶了,大家可以方便的找到.从这一篇开始分布式消息系统的入门. 在我们大量使用分布式数据库.分布式计算集群的时候,是否会遇到 ...

  2. MAC之查看日历

    命令:cal   查看当前月份 命令: cal  04  2001  查看2001年的4月份 echo命令: 打印信息

  3. C++中二维数组的动态分配

    C++中二维数组的动态分配 作者:   来源:csdn博客   公布者:admin 时间:2009-04-23 13:55:03   点击:115 C++中一维数组的动态分配十分经常使用,但C++刚開 ...

  4. VMware+Windgb+Win7内核驱动调试

    com1被占用了,需要用com2

  5. Iterator 迭代器模式 MD

    迭代器模式 简介 Iterator模式是行为模式之一,它把对容器中包含的内部对象的访问[委让]给外部类,使用Iterator按顺序进行遍历访问. 在程序设计中,经常有这种情况:需要从大量的数据集合中一 ...

  6. statickeyword

    static词义:静态的,可以用于修饰变量和方法,static方法块可以优先于构造函数运行. 被static修饰的变量,叫静态变量,静态变量在内存中仅仅有一份拷贝 public static Stri ...

  7. Oracle基础重点概要

    表空间                                                                 逻辑上处于数据库之下,利用表空间可以更灵活地规划数据库结构. 创 ...

  8. spark streaming的理解和应用

    1.Spark Streaming简介 官方网站解释:http://spark.apache.org/docs/latest/streaming-programming-guide.html 该博客转 ...

  9. 解决Sqlserver 2008 R2在创建登录名出错"此版本的 Microsoft Windows 不支持 MUST_CHANGE 选项。 (Microsoft SQL Server,错误: 15195)"

    错误信息:   执行 Transact-SQL 语句或批处理时发生了异常. (Microsoft.SqlServer.ConnectionInfo)   此版本的 Microsoft Windows ...

  10. bash參考手冊之六(Bash特性)

    6 Bash 特性 这部分描写叙述Bash独有的特性. *  调用Bash : Bash能够接受的命令行选项. *  Bash启动文件 : Bash何时及怎样运行脚本. *  交互Shell : 什么 ...