poj 2352 Stars 树状数组
来源:互联网 发布:阿里云域名代理 编辑:程序博客网 时间:2024/06/12 20:34
题目:
Stars
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 44999 Accepted: 19533
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.
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
51 15 17 13 35 5
Sample Output
12110
Hint
This problem has huge input data,use scanf() instead of cin to read data to avoid time limit exceed.
Source
Ural Collegiate Programming Contest 1999
分析:
y是升序的,处理时不需考虑。找x小于等于自己的就可以了。
代码:
#include<iostream>#include<cstring>#include<cstdio>#include<cstdlib>#include<ctype.h> //tower()#include<set> #include<map> #include <iomanip>// cout<<setprecision(1)<<fixed<<a;#include<vector> #include<time.h> #include<assert.h> //assert#include<cmath>#include<algorithm>#include<bitset>#include<stack>#include<queue>using namespace std;//#define ll __int64const int N=32010;const int maxn=15010;int n,a,b,c[N],ans[maxn];int sum(int i){int s=0;while(i>0){s+=c[i];i-=i&(-i);}return s;}void add(int i,int x){while(i<=N){//读入的a可以大于n c[]的大小也要改变 c[i]+=x;i+=i&(-i);}}int main(){while(~scanf("%d",&n)){//876K391MSmemset(c,0,sizeof(c));memset(ans,0,sizeof(ans));for(int i=1;i<=n;++i){scanf("%d%d",&a,&b);add(a+1,1);//树状数组要避免 x=0 的情况 ans[sum(a+1)-1]++; //sum()统计出的包含自己 }for(int i=0;i<n;++i){printf("%d\n",ans[i]);}}return 0;}
0 0
- POJ 2352 Stars 树状数组
- POJ 2352 Stars【树状数组】
- (树状数组) poj 2352 Stars
- POJ-2352-Stars-树状数组
- POJ 2352 Stars 树状数组
- POJ 2352 Stars 【树状数组】
- POJ 2352 Stars 树状数组
- POJ-2352 Stars【树状数组】
- POJ 2352 Stars 树状数组
- poj 2352 Stars 树状数组
- poj 2352 Stars 树状数组
- POJ:2352 Stars(树状数组)
- [树状数组]POJ 2352 Stars
- POJ-2352-Stars 树状数组
- Stars - POJ 2352 树状数组
- poj 2352 Stars 树状数组
- poj 2352 Stars (树状数组)
- POJ 2352 Stars【树状数组】
- jQuery-快速实现多级菜单效果
- CentOS7 下Redis的安装以及使用
- C++快速温习笔记(高级)[4]
- 【VS开发】【OpenGL开发】OpenGL---Windows下配置与第一个OpenGL程序
- Java常用类的知识点
- poj 2352 Stars 树状数组
- 前端开发IDE Webstorm使用技巧 2017年1月31日
- 暴露问题是对项目验收最起码的尊重!
- javascript笔记--(第一章)javascript概述
- 1026. 程序运行时间(15)
- 使用DISPATCH_SOURCE_TYPE_DATA_ADD派发源
- 【Java语言程序设计(基础篇)第10版 练习题答案】Practice_9_5
- 振兴中华 蓝桥杯
- 揭开深度增强学习的神秘面纱