Stars

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

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
 
题意:
给出N个星星的坐标,给出顺序是先按Y从小到大,后按X从小到大。问在某颗星星的左下方分别有0,1,2,.....n-1颗星星的星星坐标有几个,例如上面左下方有0课星星的有1号这一个,左下方有1颗星星的有2号和4号这两个。
代码:
 //坑爹的题,竟然已经按y,x排好序了,本想用二维树状数组。坑爹这题竟然ac了之后才有思路,首先按y排好序右安x值排好序了这样
//只需要每输入一个算一个就行,因为y相同的不用解释,y不同的后输入的Y大于前面的,X值同样也大于他左边的。
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int A[];
int lowbit(int x)
{
return x&(-x);
}
void add(int idx)
{
for(int i=idx;i<=;i+=lowbit(i))
A[i]++;
}
int sum(int idx)
{
int s=;
for(int i=idx;i>;i-=lowbit(i))
s+=A[i];
return s;
}
int main()
{
int n,a,b,c,cnt,t;
int ans[];
while(scanf("%d",&n)!=EOF)
{
memset(A,,sizeof(A));
memset(ans,,sizeof(ans));
for(int i=;i<=n;i++)
{
scanf("%d%d",&a,&b);
add(a+);
ans[sum(a+)]++; }
for(int i=;i<=n;i++)
printf("%d\n",ans[i]);
}
return ;
}

HDU1541 树状数组的更多相关文章

  1. hdu1541树状数组(降维打击)

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1541/ 题意是:在二维图上有一系列坐标,其中坐标给出的顺序是:按照y升序排序,如果y值相同则按照x升序排序.这个 ...

  2. HDU1541 经典树状数组

    HDU1541 题意: 如图,等级为0的点有1,等级为1得点有4,2  等级为2的点有3,等级为3的点有5-------即即左下角的点的个数 现给你一些点(x,y),输入顺序按y升序,y相等时按x升序 ...

  3. HDU-1541 Stars 树状数组

    题目链接:https://cn.vjudge.net/problem/HDU-1541 题意 天上有许多星星 现给天空一个平面坐标轴,统计每个星星的level, level是指某一颗星星的左下角(x& ...

  4. hdu1541 Stars 树状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目大意就是统计其左上位置的星星的个数 由于y已经按升序排列,因此只用按照x坐标生成一维树状数组 ...

  5. 树状数组入门 hdu1541 Stars

    树状数组 树状数组(Binary Indexed Tree(B.I.T), Fenwick Tree)是一个查询和修改复杂度都为log(n)的数据结构.主要用于查询任意两位之间的所有元素之和,但是每次 ...

  6. BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]

    1103: [POI2007]大都市meg Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2221  Solved: 1179[Submit][Sta ...

  7. bzoj1878--离线+树状数组

    这题在线做很麻烦,所以我们选择离线. 首先预处理出数组next[i]表示i这个位置的颜色下一次出现的位置. 然后对与每种颜色第一次出现的位置x,将a[x]++. 将每个询问按左端点排序,再从左往右扫, ...

  8. codeforces 597C C. Subsequences(dp+树状数组)

    题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. BZOJ 2434: [Noi2011]阿狸的打字机 [AC自动机 Fail树 树状数组 DFS序]

    2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 2545  Solved: 1419[Submit][Sta ...

随机推荐

  1. 清北学堂模拟赛day7 错排问题

    /* 考虑一下已经放回m本书的情况,已经有书的格子不要管他,考虑没有书的格子,不考虑错排有(n-m)!种,在逐步考虑有放回原来位置的情况,已经放出去和已经被占好的格子,不用考虑,剩下全都考虑,设t=x ...

  2. HTTP请求报文格式

    HTTP报文是面向文本的,报文中的每一个字段都是一些ASCII码串,各个字段的长度是不确定的.HTTP有两类报文:请求报文和响应报文. 请求报文 一个HTTP请求报文由请求行(request line ...

  3. synchronized在jvm底层是如何实现的

    目前在Java中存在两种锁机制:synchronized和Lock,Lock接口及其实现类是JDK5增加的内容,其作者是大名鼎鼎的并发专家Doug Lea.本文并不比较synchronized与Loc ...

  4. 基于分类的Vad效果

    提取出频谱特征,然后使用gmm.svm.dnn模型进行训练和分类,实时话语检测. 原始文件 VAD处理,剔除静音后的效果:

  5. Gossip算法

    Gossip算法因为Cassandra而名声大噪,Gossip看似简单,但要真正弄清楚其本质远没看起来那么容易.为了寻求Gossip的本质,下面的内容主要参考Gossip的原始论文:<<E ...

  6. java24

    1:多线程(理解)    (1)JDK5以后的针对线程的锁定操作和释放操作        Lock锁    (2)死锁问题的描述和代码体现    (3)生产者和消费者多线程体现(线程间通信问题)   ...

  7. 使用emIDE创建STM32项目

    emIDE是一个开源的嵌入式集成开发环境,基于Code::Blocks开发,能够支持多个平台和多个厂家的嵌入式硬件,继承了Code::Blocks的有点. 下载emIDE并安装,也可选择绿色版.若需要 ...

  8. Revolving Digits(hdu 4333)

    题意:就是给你一个数字,然后把最后一个数字放到最前面去,经过几次变换后又回到原数字,问在这些数字中,比原数字小的,相等的,大的分别有多少个.比如341-->134-->413-->3 ...

  9. Multiple dex files define Lcom/google/zxing/BarcodeFormat

    解决zxing “Could not find class 'com.goole.zxing.Result”和“Multiple dex files define”问题 时间 2014-04-24 1 ...

  10. PHP面试题4

    在PHP中,当前脚本的名称(不包括路径和查询字符串)记录在预定义变量(1)中:而链接到当前页面的URL记录在预定义变量(2)中. 答:echo $_SERVER['PHP_SELF']; echo $ ...