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. 一个很全的VTK实例网址

    https://cmake.org/Wiki/VTK/Examples/Cxx#Visualization

  2. itrator控制迭代次数

    <s:iterator value="diys" status="d" begin="0" end="10" st ...

  3. 【阮一峰】深入研究URL编码问题及JavaScript相应的解决方案

    作者: 阮一峰 日期: 2010年2月11日 一.问题的由来 URL就是网址,只要上网,就一定会用到. 一般来说,URL只能使用英文字母.阿拉伯数字和某些标点符号,不能使用其他文字和符号.比如,世界上 ...

  4. Spring中的JdbcTemplate使用

    1.引出SpringJDBC的概念 在学习JDBC编程时我们会感觉到JDBC的操作是多么繁琐,那么当我们学习的Hibernate框架时,我们感觉到数据库的操作也变非常简单,提高了开发效率.但是当使用H ...

  5. python练手基础

    Python相关文档0.1. Python标准文档0.2. Python实用大全0.3. 迷人的Python0.4. 深入理解Python0.5. Python扩展库网址 http://pypi.py ...

  6. javascript基础05

    javascript基础05 1.变量的作用域 变量既可以是全局,也可以是局部的. 全局变量:可以在脚本中的任何位置被引用,一旦你在某个脚本里声明了全局变量,你就可以 在这个脚本的任何位置(包括函数内 ...

  7. javascript基础06

      javascript基础06 splice var del_arr = del.splice(0,2); //删除从指定位置deletePos开始的指定数量deleteCount的元素,数组形式返 ...

  8. 【Python基础学习五】列表,元祖,字典

    1.列表(list) 列表是Python的一种内置数据类型,list是一种有序的集合,可以随时添加和删除其中的元素,就像动态数组一样.获取list中的元素用角标获取,角标可以使用正角标,也可以使用负角 ...

  9. servlet 之 response 回复 字节流 字符流

    重定向 设置状态吗为302  添加响应头Location(告诉他重定向到哪里去)           //response.setStatus(302);         //添加响应头Locatio ...

  10. centOS 虚拟机设置固定IP:图形化设置

    右键单击图形化标志,Edit Connection 设置一下就可以了.