博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdoj 1541 stars(树状数组)
阅读量:4544 次
发布时间:2019-06-08

本文共 2280 字,大约阅读时间需要 7 分钟。

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
 
POJ 2352 Stars题目大意:点的左下方的点数代表这个点的级数,问0~N-1的级数有多少个?坐标按照Y升序,Y相同X升序的顺序给出由于 y坐标是升序的且坐标不重复,所以在星星A后面输入的星星的x,y坐标不可能都小于等于星星A。假如当前输入的星星为(3,3),易得我们只需要去找 树状数组中小于等于3的值就可以了
1 //星星坐标的输入可以是(0,0),x坐标统一加1后用树状数组 2 #include 
3 #include
4 using namespace std; 5 #define N 150000 6 int x,y,n; 7 int c[N],s[N]; 8 #define lowbit(x) x&(-x) 9 void insert(int x,int z){10 for(int i=x;i<=60000;i+=lowbit(i)){11 c[i]+=z;12 }13 }14 int ask(int x){15 int ans=0;16 for(int i=x;i>0;i-=lowbit(i))17 ans+=c[i];18 return ans;19 }20 int main(){ 21 int x,y;22 scanf("%d",&n);23 for(int i=1;i<=n;i++){24 scanf("%d%d",&x,&y);25 ++x;26 insert(x,1);27 s[ask(x)-1]++;28 }29 for(int i=0;i

 

 
 
 
 

转载于:https://www.cnblogs.com/z-712/p/7305352.html

你可能感兴趣的文章
Spring MVC之@RequestParam @RequestBody @RequestHeader 等详解
查看>>
linux下vi命令大全
查看>>
Android使用UncaughtExceptionHandler捕获全局异常
查看>>
Codeforces Round #262 (Div. 2)
查看>>
第五章 引用类型> Data类型
查看>>
HBase学习笔记
查看>>
mybatis中的#和$的区别
查看>>
杂项收集,包括-发邮件、二维码生成、文件下载、压缩、导出excel
查看>>
封装是java面向对象编程三大特征之一。 简单的属性封装
查看>>
HTML中特殊符号的处理
查看>>
获取浏览器高宽
查看>>
C++ 智能指针
查看>>
IOS7 position:fixed 定位问题
查看>>
12.伪类选择器与伪元素的应用
查看>>
Oracle存储过程基本语法
查看>>
JS高程第八章 BOM
查看>>
python-vi
查看>>
Unix进程控制
查看>>
DNS解析过程详解
查看>>
51Nod 1181 质数中的质数(质数筛法)
查看>>