HDU 1541 Stars (树状数组)

HDU 1541 Stars (树状数组)

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

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.

HDU 1541 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

 

直接统计不大于当前数的个数,然后hash记录。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <stack>
#include <cctype>
#include <algorithm>
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
using namespace std;
typedef long long LL;
const int mod = 99999997;
const int MAX = 0x3f3f3f3f;
const int maxn = 15050;
const int N = 32005;
int n, a, b;
int c[N], ans[maxn];
int main()
{
    while(~scanf("%d", &n)) {
        memset(c, 0, sizeof(c));
        memset(ans, 0, sizeof(ans));
        int k = 0;
        for(int i = 1; i <= n; i++) {
            scanf("%d%d", &a, &b); a++;
            int sum = 0;
            for(int j = a; j > 0; j -= j&(-j)) sum += c[j];
            for(int j = a; j <= N; j += j&(-j)) c[j]++;
            ans[sum]++;
        }
        for(int i = 0; i < n; i++) printf("%d\n", ans[i]);
    }
    return 0;
}



版权声明:本文博主原创文章,博客,未经同意不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117088.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 高通mdp_高通骁龙6150

    高通mdp_高通骁龙6150引言样机上电之后如何自动选择合适的网络进行附着,如何对选择的小区确实是否可以驻守,本文将以高通平台为例,讲述从识别SIM开始,到注册到合适的小区这整个流程。架构LTE协议栈基本分为NAS(Non-Access-stratum),AS(Access-stratum),PHY,在高通平台中的基本架构如下图:其中Callmanager为上层APP,这部分还…

    2022年10月7日
    3
  • X86_64平台上利用qemu安装aarch64架构的虚拟机「建议收藏」

    X86_64平台上利用qemu安装aarch64架构的虚拟机「建议收藏」前一段时间摸索了以下在x86平台上安装arm架构(包括aarch64和armhf)的虚拟机,中间遇到了不少问题。把经验总结下来希望能帮到大家。1.安装qemu-system-aarch642.UEFI固件下载3.操作系统下载4.创建虚拟硬盘5.虚拟机安装6.虚拟机启动6.利用virt-manager启动虚拟机7.参考链接1.安装qemu-system…

    2022年10月17日
    1
  • 7月13一个不平凡的日子

    7月13一个不平凡的日子7月13一个不平凡的日子,3点起床去海淀医院吊瓶,7点到家补觉。全天共接到10电话(其中1个是骚扰)。13点到单位办请假手续,15点去乐成产品部参观并开会,里面样衣样鞋真多,真想拿几件走。…

    2022年7月16日
    14
  • maven中jar和war的区别

    maven中jar和war的区别jar文件包括java普通类、资源文件和普通文件,在maven中即是打包src/main/java和src/main/resources资源文件夹下的所有文件。在打包的时候会自动生成MATA-INF文件夹,用于存储maven的pom信息和MANIFEST.MF文件。例如:war文件包含全部的web应用程序,即所有的java类,配置信息和jsp、js等静态资源。但是需要注意war

    2022年5月23日
    79
  • 在活动目录中,转移和占用操作主机角色(转移)

    在活动目录中,转移和占用操作主机角色(转移)

    2022年3月4日
    37
  • settimeout()停止_需求方案

    settimeout()停止_需求方案转载https://aotu.io/notes/2017/09/25/manage-setTimeout-an-setInterval/在管理setTimeout&amp;setInterval这两个APIs时,笔者通常会在顶级(全局)作用域创建一个叫 timer 的对象,在它下面有两个数组成员——{sto,siv},用它们来分别存储需要管理的setTimeoutID/…

    2022年10月3日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号