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. JSON.parse()和jQuery.parseJSON()的区别

    jQuery.parseJSON(jsonString) : 将格式完好的JSON字符串转为与之对应的JavaScript对象   (jquery 方法) 1 2 3 var str = '[{&qu ...

  2. 【BZOJ】【1072】【SCOI2007】排列perm

    暴力 ……傻逼题我还WA了这么多次(有几次是忘了删调试信息……sigh) 直接统计0~9各有多少个,枚举数字就行了……因为是直接枚举的数字,而不是枚举用了s中的哪一位,所以是不用去重的!(我一开始写的 ...

  3. Winform中产生验证码图片

    1.创建ValidCode类: public class ValidCode { #region Private Fields private const double PI = 3.14159265 ...

  4. Trapping Rain Water leetcode java

    题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, co ...

  5. WebView 加载网页 加载资源 总结 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  6. (转)U3D不同平台载入XML文件的方法——IOS MAC Android

    自:http://www.cnblogs.com/sifenkesi/archive/2012/03/12/2391330.html 在PC上和IOS上读取XML文件的方式略有差别,经测试,IOS上不 ...

  7. 体绘制(Volume Rendering)概述之4:光线投射算法(Ray Casting)实现流程和代码(基于CPU的实现)

    转自:http://blog.csdn.net/liu_lin_xm/article/details/4850630 摘抄“GPU Programming And Cg Language Primer ...

  8. json数据的用法

    json数据在后台跟前台传递数据使用是非常多站点开发者再熟悉只是的数据格式了,可是呢在这之前肯定有不少人还不知道json数据是怎么使用的, {"name":"01&quo ...

  9. Silverlight 之 断点调试

    silverlight程序经常会遇到无法调试的情况,下面来总结解决方案. 一.问题描述 在Silverlight开发过程中,经常时不时的会碰到Silverlight无法调试的问题.如下几种情况: 1. ...

  10. 【Qt】splitter

    一段简单的切割窗体的程序: <span style="font-size:18px;">#include "mainwindow.h" #inclu ...