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. Android之zip包换肤(极力推荐)

    转自:http://www.eoeandroid.com/thread-102536-1-1.html 直接上图,以图为证,哈哈 第一图为原始的皮肤:<ignore_js_op> 第二种为 ...

  2. Android图片加载框架最全解析(一),Glide的基本用法

    现在Android上的图片加载框架非常成熟,从最早的老牌图片加载框架UniversalImageLoader,到后来Google推出的Volley,再到后来的新兴军Glide和Picasso,当然还有 ...

  3. Windows 7系统垃圾清理自写程序

    系统清理.bat @echo off color 0a title windows7系统垃圾清理--- echo ★☆ ★☆ ★☆ ★☆ ★☆★☆★☆ ★☆ ★☆ ★☆ ★☆★ echo ★☆ ★☆ ...

  4. 新买的mac笔记本,发现vi编辑器没有颜色的解决方案

    新买的mac笔记本,发现vi编辑器没有颜色的解决方案 我在网络上找了一些资料,发现都有些问题,尤其是一些让修改根目录上的文件,发现根本无法修改. 但是在网络上找到了这篇文章: http://super ...

  5. 游戏:贪吃虫(GreedyMaggot)

    该游戏类似于贪吃蛇,但可以在二维平面上以任意方向前进.当吃到食物手,食物会从虫头向虫尾移动,移到虫尾后,贪吃虫长度会增加.本来给它取名为贪吃蛆的,并且工程的英文名Maggot就是蛆的意思,后来想想有点 ...

  6. windows media server 组件安装后流媒体服务器启动失败

    做好的web应用,去客户现场部署的时候发现流媒体服务器不能启动.(现场服务器系统为windows server2008 R2) 自己测试的时候搭建环境没什么问题.从来没有遇到安装windows med ...

  7. go语言基础之切片和底层数组关系

    1.切片和底层数组关系 示例: package main //必须有个main包 import "fmt" func main() { a := []int{0, 1, 2, 3, ...

  8. Android之WifiManager

    移动设备离不开网络,android平台中在包android.net.wifi下提供了一些类专门用于管理设备的Wifi功能.该包下主要存在如下几个类: 1.  ScanResult:主要用来描述通过Wi ...

  9. 怎样在Ubuntu中修改默认程序

    这个新手指南会向你展示如何在 Ubuntu Linux 中修改默认程序.对于我来说,安装 VLC 多媒体播放器是安装完 Ubuntu 16.04 该做的事中最先做的几件事之一.为了能够使我双击一个视频 ...

  10. 使用Zxing开发Air版二维码扫描工具

    简介实现的核心要点和几个须要注意的问题: 使用开源类库:Zxing,微信也是用的这个.下载地址:http://code.google.com/p/zxing/ as版:https://github.c ...