HDU1541 树状数组
Stars
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8938 Accepted Submission(s): 3551
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.
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 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.
//坑爹的题,竟然已经按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 树状数组的更多相关文章
- hdu1541树状数组(降维打击)
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1541/ 题意是:在二维图上有一系列坐标,其中坐标给出的顺序是:按照y升序排序,如果y值相同则按照x升序排序.这个 ...
- HDU1541 经典树状数组
HDU1541 题意: 如图,等级为0的点有1,等级为1得点有4,2 等级为2的点有3,等级为3的点有5-------即即左下角的点的个数 现给你一些点(x,y),输入顺序按y升序,y相等时按x升序 ...
- HDU-1541 Stars 树状数组
题目链接:https://cn.vjudge.net/problem/HDU-1541 题意 天上有许多星星 现给天空一个平面坐标轴,统计每个星星的level, level是指某一颗星星的左下角(x& ...
- hdu1541 Stars 树状数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目大意就是统计其左上位置的星星的个数 由于y已经按升序排列,因此只用按照x坐标生成一维树状数组 ...
- 树状数组入门 hdu1541 Stars
树状数组 树状数组(Binary Indexed Tree(B.I.T), Fenwick Tree)是一个查询和修改复杂度都为log(n)的数据结构.主要用于查询任意两位之间的所有元素之和,但是每次 ...
- BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]
1103: [POI2007]大都市meg Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2221 Solved: 1179[Submit][Sta ...
- bzoj1878--离线+树状数组
这题在线做很麻烦,所以我们选择离线. 首先预处理出数组next[i]表示i这个位置的颜色下一次出现的位置. 然后对与每种颜色第一次出现的位置x,将a[x]++. 将每个询问按左端点排序,再从左往右扫, ...
- codeforces 597C C. Subsequences(dp+树状数组)
题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...
- BZOJ 2434: [Noi2011]阿狸的打字机 [AC自动机 Fail树 树状数组 DFS序]
2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 2545 Solved: 1419[Submit][Sta ...
随机推荐
- mysql 存储过程在批处理数据中的应用
最近批处理数据的时候,突然想到:为什么不使用存储过程进行数据批处理? 为什么要进行批处理? 自答:减少数据库连接次数,提高效率. 存储过程批处理数据的优点:一次编译,永久执行. 这次的批处理逻辑较简单 ...
- rqnoj378 约会计划
题目描述 cc是个超级帅哥,口才又好,rp极高(这句话似乎降rp),又非常的幽默,所以很多mm都跟他关系不错.然而,最关键的是,cc能够很好的调解各各妹妹间的关系.mm之间的关系及其复杂,cc必须严格 ...
- WP8下实现刮刮乐(橡皮擦)功能
说到刮刮乐这个功能,我们最先想到的是上下两张(长方形)重叠,之后对上面这张图片进行操作. 我的想法是:通过手势,让手指划过的地方变成透明的,底部就会显示了. 那如何让图片变为透明呢?这就要对图片的像素 ...
- 1.3为WebApi创建帮助文档
当你创建一个网络 API 时,它很有用来创建一个帮助页,以便其他开发人员将知道如何调用您的 API.您可以创建的所有文档手动,但它是自动生成尽可能多地更好. 为了简化这一任务,ASP.NET Web ...
- iOS抓包利器Charles
iOS抓包利器Charles http://wonderffee.github.io/blog/2013/07/13/best-packet-capture-tool-charles-in-ios/ ...
- phpcms中的RBAC权限系统
PHPCMS中的RBAC权限系统主要用到了4张数据表:管理员表,角色表,菜单表,菜单权限表.先来看看数据库的数据表结构: admin 管理员表 ID 字段 类型 Null 默认 索引 额外 注释 1 ...
- canvas的简单圆形进度条
window.onload = function(){ function arc(canvas,number){ var canvas = document.getElementById(canvas ...
- jquery 赋值文本框输入框
jQuery("#mrId option[value='" + extValue + "']").attr("selected", true ...
- angularjs里对JS的lowercase和uppercase的完善
读angularjs的源码开头. var lowercase = function (string) { return isString(string) ? string.toLowerCase() ...
- How-to-uninstall-Meteor // install Meteor manually
How-to-uninstall-Meteor : http://www.uninstallapp.com/article/How-to-uninstall-Meteor-.html install ...