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. C++运算符重载(友元函数方式)

    我们知道,C++中的运算符重载有两种形式:①重载为类的成员函数(见C++运算符重载(成员函数方式)),②重载为类的友元函数. 当重载友元函数时,将没有隐含的参数this指针.这样,对双目运算符,友元函 ...

  2. 数据库实例: STOREBOOK > 表空间 > 编辑 表空间: USERS

    ylbtech-Oracle:数据库实例: STOREBOOK  >  表空间  >  编辑 表空间: USERS 表空间  >  编辑 表空间: USERS 1. 一般信息返回顶部 ...

  3. c++学习之友元

    最近工作好累呀,晚上总是失眠,自学c++的步骤都放慢了,本来之前看c++ primer的,结果这本书讲的太细节了,初学者不是很好把握.所以我又重新找了个教程,比较适合初学者.今天学习到友元函数和友元类 ...

  4. C++分布式实时应用框架——系统管理模块

    一个分布式实时系统集群动辄上百台机器,集群的规模已经限定这将是一个”封闭“的系统.你不可能再一台台去操作上百台机器,传统的人工运维方式早已不能满足当下需要,所有对集群或者集群中某个节点的操作都必需通过 ...

  5. javascript制作公式编辑器,函数编辑器和图形绘制

    自己是电子信息方向的,因此总是需要处理大量的电路实验.电路数据和电路仿真处理,每次处理数据时候还需要同样的数据很多遍, 又需要关于电路的频率响应和时域响应情况,所以一直有做一个这样公式编辑器的打算了. ...

  6. Java基础(六):继承

    1.继承的概念: 继承是java面向对象编程技术的一块基石,因为它允许创建分等级层次的类.继承就是子类继承父类的特征和行为,使得子类对象(实例)具有父类的实例域和方法,或子类从父类继承方法,使得子类具 ...

  7. 火速提升Android仿真器的运行速度 ——仿真器Genymotion

    一.问题概述 Android开发中会使用仿真器测试应用,但不管你使用Eclispe ADT还是Android Studio仿真器都是基于arm架构的,运行起来都很慢,光启动就要花费很多时间,都不知道它 ...

  8. tiny210(s5pv210)移植u-boot(基于 2014.4 版本号)——移植u-boot.bin(打印串口控制台)

    在之前我们移植的代码中,都没看到明显的效果,这节我们实现控制台的信息打印. 在上节.我们看到调用 relocate_code 重定位.在 u-boot 的帮助文档 doc/README.arm-rel ...

  9. iOS8开发~Swift(二)Playground

    一.Playground介绍 Playground是Xcode6中自带的Swift代码开发环境.俗话说"功欲善其事,必先利其器".曾经在Xcode5中编写脚本代码.比如编写JS.其 ...

  10. ZH奶酪:通过CSS自定义HTML中hr样式-颜色-形状

    修改颜色,线条形状,粗细等... CSS代码: .zh_hr{ border:3px solid rgba(255, 255, 255, 0.50); margin-bottom: 2px; marg ...