POJ 2352 Stars

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: 23114 Accepted: 10077

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.

树状数组

#include<stdio.h>
#include<string.h>

#define MAXN 32002

int c[MAXN];
int s[MAXN];

int lowbit(int x)
{
    return x&(-x);
}

void update(int x)
{
    while(x<MAXN)
    {
        c[x]++;
        x+=lowbit(x);
    }
}

int sum(int end)
{
    int s=0;
    while(end>0)
    {
        s+=c[end];
        end-=lowbit(end);
    }
    return s;
}

int main(void)
{
    int N,i,x,y,k;
//    memset(c,0,sizeof(c));
//    memset(s,0,sizeof(s));
    scanf("%d",&N);
    for(i=1;i<=N;i++)
    {
        scanf("%d%d",&x,&y);
        update(x+1);
        k=sum(x+1)-1;
        s[k]++;
    }
    for(i=0;i<N;i++)
    {
        printf("%d\n",s[i]);
    }

    return 0;
}



POJ - 2352:Stars POJ-2352:Stars 来源:POJ 标签:树状数组 参考资料: 相似题目: 题目 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... 阅读详情

相关推荐

扣子(coze)实战|手把手教你搭建AI换装自动化工作流

摘要:本文介绍了使用Coze平台搭建AI换装工作流的详细教程。工作流包含模特图片上传、服装替换、任务提交和智能轮询等模块,通过change_model插件实现异步换装处理,并内置30秒循环查询机制。该工具支持自定义API密钥对接不同AI服务商,目前已上线共享空间并提供会员服务(59.8元/年)和VIP课程(499元/年),包含100+智能体和实战案例资源。完整体验地址见文中链接。

yueyehuguang的博客 1856

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 331

Synopsys 逻辑综合之 ICG

文章摘要: ICG(集成时钟门控单元)是一种用于降低时钟功耗的专用逻辑单元,通过控制时钟信号的传播实现节能。其核心原理是在寄存器前插入门控逻辑(如gclk=clk&en),但需避免直接使用AND门以防止毛刺,转而采用带锁存器的专用ICG单元。在RTL设计中,符合条件(如稳定使能信号)的if(en)结构可被综合工具(如DesignCompiler)自动识别并替换为ICG。使用时需配置时序检查(如PrimeTime分析使能路径、门控时钟延迟),并注意避免组合逻辑使能、多级门控等误区。ICG是芯片低功耗设

Serven的博客 4381

POJ-2352-Stars

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

菜鸟的程序人生 2434

ENVI-met新手必看:从零开始创建城市微气候模型(附详细步骤+底图制作技巧)

本文为ENVI-met新手提供从零开始创建城市微气候模型的详细指南,包括环境准备、参数配置、底图制作技巧和三维模型构建步骤。特别针对常见问题提供解决方案,帮助初学者快速掌握城市微气候模拟技术,提升建模效率。

weixin_29269441的博客 414

从IPv6到Tomcat:彻底解决127.0.0.1拒绝连接的完整指南

本文提供了从IPv6到Tomcat的全面指南,帮助开发者彻底解决127.0.0.1拒绝连接的问题。涵盖网络协议栈、服务配置、端口管理等多个层面的排查方法,特别针对Tomcat服务提供了专项解决方案,确保开发者能够快速定位并修复连接问题。

weixin_29207439的博客 495

poj 2352 Stars(线段树)

poj 2352 Stars(线段树)

PKU_ZZY的博客 886

MPC模型预测控制实战:从理论到代码实现(Python示例)

本文详细介绍了MPC模型预测控制的实战应用,从理论到Python代码实现。通过构建系统模型、预测方程、优化问题及约束处理,展示了如何实现一个完整的MPC控制器。文章还提供了水箱液位控制的应用案例,帮助读者掌握MPC在工业控制中的实际应用。

weixin_42653691的博客 468

树状数组 poj2352 Stars

2019-05-20 22:52:07 加油,坚持,加油,坚持 !!! #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int MAXN = 32005; int c[MAXN],level[MAXN],n; ...

weixin_30662109的博客 92

MC33PT2000控制详解一:PT2000 Dev Studio工具的使用

MC33PT2000共可控制6个高低端(如控制6个高压喷油器),1个高低端(如控制高压油泵)和DC-DC模块(如升压到65V).

m0_69929716的博客 1368

【重启后nvidia-smi 命令出现错误】

NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

qq_44769377的博客 5225

【树状数组】POJ 2352 Stars

POJ 2352 Stars 题意:在笛卡尔坐标系上给出星星坐标,按照y坐标升序(y坐标相等,x坐标升序)给出。规定星星的等级为其左下方的星星数量,求各等级的星星的个数。 思路:由于星星是按照y坐标升序(y坐标相等,x坐标升序)给出的,所以我们找该星星的左下的星星数量,就是当前输入该星星坐标之后getsum(x)-1,“-1”是因为要减去该星星本身。 注意:为了防止add( 0 ),所以我们每个...

L_X_ 168

【GEOS-Chem模拟教程第二期上】生物质燃烧排放 GFED4 数据配置

生物质燃烧排放 GFED4 数据配置

WW、forever的博客 1310

POJ2352 Stars

题目大意: 在坐标上有n个星星,如果某个星星坐标为(x, y), 它的左下位置为:(x0,y0),x0 按照y递增,如果y相同则x递增的顺序给出n个星星,求出所有level水平的数量。 一维的树状数组,

alpc_wt的专栏 634

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

POJ 2352 Stars (线段树)

POJ 2352 Stars (线段树) 手动博客搬家:本文发表于20170819 22:11:49, 原地址https://blog.csdn.net/suncongbo/article/details/77417650 URL: http://poj.org/problem?id=2352 题目大意:给定n个点(n<=15000), 每个点有坐标(x, y...

suncongbo's blog 112

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

POJ 2352 Stars(树状数组)

题目链接: POJ 2352 Stars 题意: 每个星星的level是纵坐标小于等于它并且横坐标小于它的星星的数量。按照y从小到大,其次x从小到大的顺序给出n个星星的坐标,输出level从0到n-1的星星的数量。 分析: 由于给出的坐标是优先按照y排序的,那么直接对每个星星查找x的树状数组值然后更新就好了。//556K 375MS #include <cstdio> #include <

ramay7 450

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

【POJ2352】Stars(树状数组模版题)

题目:https://vjudge.net/problem/POJ-2352 题意: 夜空中有N颗恒星(N≤100000),每颗恒星具有其坐标(x, y)(0≤x, y≤100000)。现在,天文学家要对这些恒星进行分类,分类的标准如下:对于任意一颗恒星S(x,y),如果存在k颗恒星,其x, y坐标均不大于S,则恒星S属于k类星。 如下图所示:第5颗恒星为3类星,这是由1、2、4三颗恒星均在其...

Cassie_zkq的博客 599

poj2352&hdu1541stars(树状数组)

poj2352stars 题目描述: 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

luckcircle的博客 556
上一篇: Hdu 2639 Bone Collector II
下一篇: 皮克定理
Magic_____
博客等级 码龄14年 11粉丝 160原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址