POJ2352

POJ-2352(Stars)树状数组解法 题目原网址:http://poj.org/problem?id=2352又是一道星星的题,下面是题目描述(本人翻译):题目描述天文学家经常检查星图,其中恒星由平面上的点表示,每颗恒星都有笛卡尔坐标。让恒星的水平是恒星的数量,而恒星并不高于恒星的右边。天文学家想知道恒星的分布。例如,查看上图中显示的地图。星号5的水平等于3(它由三颗星形成,数字为1,2和4)。而且,编号为2和4的恒星的等级为1.在该... 阅读详情
Stars
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 36355 Accepted: 15810

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

Hint

This problem has huge input data,use scanf() instead of cin to read data to avoid time limit exceed.



簡單地讀一下題目意思就是紅色那段說的4和2的level是1,5的level是3,所以就是統計一下該點的左下角星星個數,然後輸出那個lvevl的星星數目。
#include<stdio.h>
#include<stdlib.h>
#define MAX 32005
int a[MAX]= {0},c[MAX]= {0};
int lowbit(int x)
{
    return x&(-x);
}
int sum(int i)
{
    int s;
    while(i>0)
    {
        s=s+c[i];
        i=i-lowbit(i);
    }
    return s;
}
void add(int x)
{
    while(x<=MAX)
    {
        ++c[x];
        x=x+lowbit(x);
    }
}
int main()
{
    int x,y,i,n;
    scanf("%d",&n);
    for(i=0; i<MAX; i++)
        a[i]=c[i]=0;
    for(i=0; i<n; i++)
    {
        scanf("%d%d",&x,&y);
        a[sum(++x)]++;
        add(x);
    }
    for(i=0; i<n; i++)
    {
        printf("%d\n",a[i]);
    }
    return 0;
}


MTK MT6833平台屏幕与TP驱动移植实战:从FAE伪代码到内核模块集成 本文详细介绍了在MTK MT6833平台上进行屏幕与TP驱动移植的完整实战流程。文章从解析供应商提供的初始化伪代码入手,逐步拆解了在LK阶段点亮屏幕、在内核层集成Panel驱动以支持休眠唤醒,以及移植并调试sitronix_ts触摸驱动的核心步骤与关键技巧,为嵌入式开发人员提供了从零到一集成新硬件的清晰指南。 阅读详情

相关推荐

python知网爬虫论文pdf下载+立即可用(动态爬虫)

python实现动态爬虫知网论文,搜索+自动翻页+下载 收集数据利器

Braylon的博客 5379

poj 2352 Stars(线段树)

poj 2352 Stars(线段树)

PKU_ZZY的博客 885

从TCGA官网获取新版count数据并精准转换为TPM的实战指南

本文详细介绍了从TCGA官网获取新版count数据并精准转换为TPM的实战指南。通过TCGAbiolinks工具下载原始count数据,结合GENCODE v36注释文件计算基因有效长度,最终实现count到TPM的标准化转换,确保数据完整性和分析可靠性。文章包含完整代码示例和常见问题解决方案,特别适合生物信息学研究人员参考。

weixin_27310417的博客 283

POJ 2352

---恢复内容开始--- http://poj.org/problem?id=2352 这是一个树状数组的题目,也是我第一次接触这类的题目,也正是因为之前的一道题,TLE了,超时太严重了,我看discuss里再说什么用树状数组可以我才去找有关于这方面的博客看 看了很多博客才稍微的理解了一点树状数组,可以在以后的做题中,加强对这个的理解 这个图片就是数组数组的...

A1823085974的博客 94

USB PD Sink HUSB238A可应用于24V电动风扇/电动工具

HUSB238A在I2C模式下,可申请PD3.1 EPR AVS功率,可申请24V电压直接给电机供电

Hynetek的博客 759

Openharmony 命令行工具hdc的获取与安装

OpenHarmony实战:命令行工具hdc安装应用指南_hdc工具-优快云博客t=N7T8。

Devlin_的博客 1万+

poj2352

//poj2352求该点包含的点时所有比它低的点都已经加过 #include #include using namespace std; int a[32005]; int b[32005]; int tree[32001*4]; void Build(int p,int l,int r,int x) //先建立0~x范围的分支 { if(l==r){ tree[p]+

zizahn的博客 355

ROS——无人机ROS仿真包 rotors_simulator 编译教程

文章目录 安装wstool sudo apt install python3-wstool 创建ROS工程 $ mkdir -p ~/UAV/src $ cd ~/UAV/src $ catkin_init_workspace # initialize your catkin workspace $ wstool init 下载源码 git clone git@github.com:ethz-asl/rotors_simulator.git 源码链接: https://github.com/eth

漫长IT路 5863

POJ - 2352  Stars

POJ - 2352  Stars 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 ...

YIU 330

window系统 dlib库安装

1. 安装visual studio 1.1. 安装vs2017或以上版本 1.2. 我们需要安装使用C++的桌面开发,且必须选上用于Cmake的Visual C++工具 1.3. 安装完成后,将D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin 添加到环境变量PATH中 2 下载cmake文件,并添加环境变量 2.1 在c

@bangbang的博客 815

【Agora 本地录制最全总结- 基于Java SDK】

Agora 本地服务端录制

lizhengze1117的博客 1790

POJ 2352 Stars

POJ 2352 Stars AC代码: import java.util.Scanner; public class Main { static int maxn=32000; static int c[]=new int[maxn|1]; static Scanner scan=new Scanner(System.in); private static in

爪哇D来客 405

详解【异质图卷积网络 RGCN】回顾:图神经网络问题的三大处理步骤 | 从起源说起,RGCN核心公式解释,两种降低模型参数量/优化的方式,附核心代码实现讲解

本篇,我们深入分析和学习RGCN的原理以及为何要这么做。首先让我们来回顾对于图神经网络问题的三大处理步骤,可以说,这是该深度学习模型的基本理解,后续都是在深化其中的细节处理。然后以容易理解的方式,引出异质图卷积网络RGCN的由来,主要讲解其核心公式和论文中作者所提出的两种降低模型参数量/优化的处理办法,并给出基础分解以及块对角分解的核心实现代码讲解。最后附上RGCN源代码及说明。

追光者♂:记录、分享、总结、提升,现象级专栏《Python从入门到人工智能》作者,无惧黑暗,坚信曙光 1279

【ICPC-407】poj 2352 Stars

点击打开链接poj2352 思路:树状数组 分析: 1 题目是要求出每一个点的左下(正左+正下)有几个星星,那个这个点就是第几层,最后输出0~n-1层的点的个数。比如样列编号为5的星星,左下有3个星星那么5就处于第三层 2 利用树状数组,我们知道树状数组C中,C[i]表示的是原先数组A中的某一段和。题目明确指出输入的时候是按照y值增大的顺序(y相同是x增大),那么我们应该要用什么做为原先的数组A...

藏经阁 | 玄苦 4103

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

POJ-2352-Stars

POJ-2352-Stars http://poj.org/problem?id=2352 给出n个星星的坐标,如果一个星星的左下方(包含正左和正下)有k颗星星,就说这颗星星是k级的,统计每个等级有多少个点。这题可用树状数组,对于每个星星按y坐标从小到大排序,相同y坐标按x坐标从小到大排序(题目中数据已经有序),输入顺序已排好序,那么只要依次统计星星i之前x坐标小于等于i.x的星星有多少,即是...

java开发指南博客 【转载】 289

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

【POJ 2352】 Stars

【题目链接】 http://poj.org/problem?id=2352 【算法】 树状数组 注意x坐标为0的情况 【代码】 #include <algorithm> #include <bitset> #include <cctype&gt...

245

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

POJ 2352 Stars .

题目地址:http://poj.org/problem?id=2352 #include #include #include #include #include using namespace std; const int maxn=32000+5; int lowbit[maxn],C[maxn]; int level[maxn]; int inline getlowbit(int i) {

BRCOCOLI的博客 465

POJ2352——树状数组——Stars

http://poj.org/problem?id=2352 模板 /************************************************ * Author :Powatr * Created Time :2015-8-13 16:18:10 * File Name :POJ2352stars.cpp ********...

dgjm4087的博客 193

二维偏序 poj 2352 luogu 3431

这两题都是二维偏序,二维偏序的题怎么去做呢? 回忆一下二维偏序,可以化为这样一个问题:设一个点为(x,y),问(1 ~ x-1,1 ~ y-1)(即一个点的左下方)有多少个点? 那我们一般怎么做呢,就是固定一维(x或y)然后排序,在另一维统计答案。这么做的正确性看看题,手动模拟一下就知道了(严格证明我不知道)。 poj 2352: 很明显题目已经固定了y这一维,然后我们统计x就可以了。 #include<cstdio> #include<algorithm> #include<

qq_37073764的博客 449

poj2352(树状数组)

题目链接:https://vjudge.net/problem/POJ-2352 题意:在直角坐标系中给出n个点的 (x,y),(0<=x,y<=32000),定义每个点的level为(x',y')的数量,其中x'<=x,y'<=y。输出所有level的点的个数。 思路:这几天开始写树状数组的题,加油!!因为输入为按y升序排列,在y相等时按x升序排列。所以当输入点i时,...

weixin_33967071的博客 114
上一篇: POJ3268
下一篇: GCD
seekforcode
博客等级 码龄12年 9粉丝 41原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值