HDU 1541 Stars (树状数组)
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.
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.
5
1 1
5 1
7 1
3 3
5 5
1
2
1
1
0
直接统计不大于当前数的个数,然后hash记录。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <stack>
#include <cctype>
#include <algorithm>
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
using namespace std;
typedef long long LL;
const int mod = 99999997;
const int MAX = 0x3f3f3f3f;
const int maxn = 15050;
const int N = 32005;
int n, a, b;
int c[N], ans[maxn];
int main()
{
while(~scanf("%d", &n)) {
memset(c, 0, sizeof(c));
memset(ans, 0, sizeof(ans));
int k = 0;
for(int i = 1; i <= n; i++) {
scanf("%d%d", &a, &b); a++;
int sum = 0;
for(int j = a; j > 0; j -= j&(-j)) sum += c[j];
for(int j = a; j <= N; j += j&(-j)) c[j]++;
ans[sum]++;
}
for(int i = 0; i < n; i++) printf("%d\n", ans[i]);
}
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
HDU 1541 Stars (树状数组)的更多相关文章
- POJ 2352 && HDU 1541 Stars (树状数组)
		一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~ ... 
- hdu 1541 (基本树状数组)  Stars
		题目http://acm.hdu.edu.cn/showproblem.php?pid=1541 n个星星的坐标,问在某个点左边(横坐标和纵坐标不大于该点)的点的个数有多少个,输出n行,每行有一个数字 ... 
- HDU 1541 STAR(树状数组)
		Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ... 
- Stars(树状数组)
		http://acm.hdu.edu.cn/showproblem.php?pid=1541 Stars Time Limit: 2000/1000 MS (Java/Others) Memor ... 
- hdu1541 Stars 树状数组
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目大意就是统计其左上位置的星星的个数 由于y已经按升序排列,因此只用按照x坐标生成一维树状数组 ... 
- HDU 2838 (DP+树状数组维护带权排序)
		Reference: http://blog.csdn.net/me4546/article/details/6333225 题目链接: http://acm.hdu.edu.cn/showprobl ... 
- HDU 2689Sort it 树状数组 逆序对
		Sort it Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ... 
- POJ-2352 Stars   树状数组
		Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description A ... 
- Stars(树状数组或线段树)
		Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37323 Accepted: 16278 Description A ... 
- hdu 4046 Panda 树状数组
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4046 When I wrote down this letter, you may have been ... 
随机推荐
- js面向对象编程:命名空间
			在其它语言中为了避免类和方法重名问题,都有一个类似命名空间的概念,在js中实现类似的功能吗? 能够实现,主要是借助于js中对象的概念来实现,比如: 1 在命名空间中定义方法属性 var GiantC ... 
- hdu 4771 Stealing Harry Potter's Precious
			题目:给出一个二维图,以及一个起点,m个中间点,求出从起点出发,到达每一个中间的最小步数. 思路:由于图的大小最大是100*100,所以要使用bfs求出当中每两个点之间的最小距离.然后依据这些步数,建 ... 
- jQuery插件实战之fullcalendar(日历插件)Demo
			jQuery的插件许多,应用的场景也很丰富,今天我这里给大家介绍一款很有用的日历页面开发插件 - fullcalendar,眼下最新版本号是1.5.1,使用这款插件可以高速帮助你高速编程实现基于web ... 
- android com.handmark.pulltorefresh 使用技巧
			近期使用android com.handmark.pulltorefresh 遇到一些小问题.如今总结一些: 集体使用教程见: http://blog.csdn.net/harvic880925/ar ... 
- Android kxml解析WBXML
			WAP Binary XML定义好XML片断表述出同步server地址.远程数据库名称.登录账号等等内容一.两种訪问方法: 眼下的kxml支持两种wap格式:WBXML/WML. 而有两种方法将解析 ... 
- Linux/Unix使用valgrind内存泄漏检测
			c\c++程序设计.内存管理是一个比较头疼的问题.相信它会导致内存泄漏.除了外部养成良好的编程习惯(使用智能指针),使用该工具还可以帮助检测内存泄漏,valgrind这是Unix\Linux在一个很好 ... 
- Java RMI(远程方法调用) 实例与分析 (转)
			目的: 通过本文,可以加深对Java RMI的理解,知道它的工作原理,怎么使用等. 也为了加深我自己的理解,故整理成文.不足之处,还望指出. 概念解释: RMI(RemoteMethodInvocat ... 
- 自己写shell命令pwd
			思维:(1)得到"."的i节点号,叫n(使用stat) (2)chdir ..(使用chdir) (3)找到inode号为n的节点,得到其文件名称. 反复上述操作直到当前文件夹&q ... 
- CentOS6.5 Nginx优化编译配置[续]
			继续上文CentOS6.5 Nginx优化编译配置本文记录有关Nginx系统环境的一些细节设置,有关Nginx性能调整除了配置文件吻合服务器硬件之前就是关闭不必要的服务.磁盘操作.文件描述符.内核调整 ... 
- android 项目中设置背景图片
			xml文件设置背景图片中:任意一个控件,button imageView 或layout,在其的xml属性设置中,添加 [XML] view plaincopy android:background= ... 
