Stars

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

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
 
题意:给n个坐标,这些坐标按y值从小到大给出,每个坐标的等级就是在【0,0】~【x,y】区域内点的个数,输出每个等级有多少个点
 
题解:因为y是有序的,只考虑x就可以了,所以每个点的等级就是:之前输入的坐标x(0~i)中,x的值<=x的点有几个
再用vis[]统计每个等级的点有几个即可
 

注意:航电里面的数据范围少了一个0,0<= x,y <=320000

#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
int b[],vis[];
int lowbit(int x)//x的二进制表达中,从右往左第一个1所在的位置表示的数,返回的是这个数的十进制数
{
return x&(-x);
}
void add(int x)
{
while(x<=)
{
b[x]++;
x=x+lowbit(x);
}
}
int getnum(int x)
{
int cnt=;
while(x>)
{
cnt=cnt+b[x];
x=x-lowbit(x);
}
return cnt;
}
int main()
{
int t,x,y;
while(~scanf("%d",&t))
{
memset(vis,,sizeof(vis));
memset(b,,sizeof(b));
for(int i=;i<t;i++)
{
scanf("%d%d",&x,&y);
vis[getnum(x+)]++;//统计<=x的数有几个
add(x+);
}
for(int i=;i<t;i++)
printf("%d\n",vis[i]);
}
}

hdu 1541 Stars 统计<=x的数有几个的更多相关文章

  1. hdu 1541 Stars 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目意思:有 N 颗星星,每颗星星都有各自的等级.给出每颗星星的坐标(x, y),它的等级由所有 ...

  2. HDU 1541 Stars (树状数组)

    Problem Description Astronomers often examine star maps where stars are represented by points on a p ...

  3. hdu 1541 Stars

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 思路:要求求出不同等级的星星的个数,开始怎么也想不到用树状数组,看完某些大神的博客之后才用树状数 ...

  4. POJ 2352 &amp;&amp; HDU 1541 Stars (树状数组)

    一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~ ...

  5. HDU - 1541 Stars 【树状数组】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1541 题意 求每个等级的星星有多少个 当前这个星星的左下角 有多少个 星星 它的等级就是多少 和它同一 ...

  6. 题解报告:hdu 1541 Stars(经典BIT)

    Problem Description Astronomers often examine star maps where stars are represented by points on a p ...

  7. POJ 2352 Stars(HDU 1541 Stars)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41521   Accepted: 18100 Descripti ...

  8. HDU 1541 Stars (线段树)

     Problem Description Astronomers often examine star maps where stars are represented by points on ...

  9. hdu 1541 Stars(线段树单点更新,区间查询)

    题意:求坐标0到x间的点的个数 思路:线段树,主要是转化,根据题意的输入顺序,保证了等级的升序,可以直接求出和即当前等级的点的个数,然后在把这个点加入即可. 注意:线段树下标从1开始,所以把所有的x加 ...

随机推荐

  1. C语言-实现矩阵的转置-随机函数产生随机数并赋予数组中-190222

    //编写程序,实现矩阵的转置(行列互换). #include <stdio.h> #include <conio.h> #include <stdlib.h> ][ ...

  2. VScode Vim插件快速上手与配置

    快速安装: 打开market place,搜索vim即可安装. 基本改建与配置说明: 方向键: 用I k j l表示光标上下左右,需要编辑visual mode和normal mode { " ...

  3. 重磅消息,Micrium的uCOS全家桶将推出免费商业授权

    说明: 1.预计将在下个月末的Embedded World 2020正式宣布开源免费商用. 2.uCOS全家桶一旦宣布免费商用,将给那些还在收费的RTOS带来一波冲击.其中最值的关注的是去年微软收购T ...

  4. IIS 部署 web service

    1.在控制台检查 IIS 功能是否已经全部启用 2.重新注册IIS 3.设定程序池的正确版本

  5. ASP.NET Core搭建多层网站架构【8.2-使用AutoMapper映射实体对象】

    2020/01/29, ASP.NET Core 3.1, VS2019, AutoMapper.Extensions.Microsoft.DependencyInjection 7.0.0 摘要:基 ...

  6. RTU:EvalRightToUse License for feature adventerprise 1.0 will transition to RightToUse in 10 days. UDI ASR1002-X:JAE2100XXXX

    关于这个log:[Hostname] EvalRightToUse License for feature adventerprise 1.0 will transition to RightToUs ...

  7. 单播反向路径转发uRPF

    uRPF将数据包的源地址和存储在转发信息库(FIB)中的信息进行对照,以判定数据包的合法性.FIB是Cisco CEF技术中的一张表,包含从路由表中复制过来的转发信息,可以将其视为路由表的镜像,FIB ...

  8. 杭电2070 Fibbonacci Number

    Fibbonacci Number Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  9. Java面向对象编程 -3.3

    综合实战 简单Java类 在以后进行项目开发与设计的过程之中,简单Java类都将作为一个重要的组成部分存在,慢慢接触到正规的项目设计后, 简单Java类无处不再,并且有可能产生一系列的变化. 所谓的简 ...

  10. ➡️➡️➡️IELTS Listening

    目录 src numbers and letters src https://ielts-simon.com/ielts-help-and-english-pr/ielts-listening/ nu ...