POJ2352 Stars 树状数组
来源:互联网 发布:淘宝云客服在哪里 编辑:程序博客网 时间:2024/04/30 07:02
题目链接:POJ2352
Stars
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 45761 Accepted: 19779
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.
题意:有一个星座图,每个星星都有一个坐标,对于一个星星的等级是不高于且不右于此星星的数量,求0~n-1每个等级的数量。
题目分析:给出的数据是已经按照y轴排好序的,因此我们只需要统计序列在每个星星前且x坐标不大于的个数为这个星星的等级,套用树状数组模板,记得对0特殊处理。
//// main.cpp// POJ2352//// Created by teddywang on 2017/2/12.// Copyright © 2017年 teddywang. All rights reserved.//#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int x[40000],s[40000],r[40000],c[40000];int n;int maxn;struct node{ int x; int y;}t[40000];int lowbit(int x){ return x&(-x);}int getsum(int x){ int ans=0; while(x>0) { ans+=c[x]; x-=lowbit(x); } return ans;}void update(int x,int num){ while(x<=maxn) { c[x]+=num; x+=lowbit(x); }}int main(){ while(~scanf("%d",&n)) { memset(c,0,sizeof(c)); memset(x,0,sizeof(x)); maxn=0; for(int i=1;i<=n;i++) { scanf("%d%d",&t[i].x,&t[i].y); t[i].x++; maxn=max(maxn,t[i].x); } for(int i=1;i<=n;i++) { int num=getsum(t[i].x); update(t[i].x,1); x[num]++; } for(int i=0;i<n;i++) { printf("%d\n",x[i]); } }}
0 0
- 【树状数组】 poj2352 Stars
- POJ2352 stars(树状数组)
- poj2352 - Stars(树状数组)
- poj2352 Stars 树状数组
- POJ2352:Stars(树状数组)
- POJ2352 Stars(树状数组)
- POJ2352 Stars 树状数组
- POJ2352 Stars[树状数组]
- 【poj2352】【树状数组】Stars
- poj2352 Stars (树状数组)
- POJ2352 Stars 树状数组
- POJ2352 Stars 树状数组
- poj2352 Stars(树状数组)
- 【树状数组】poj2352 stars
- POJ2352 Stars 树状数组
- poj2352 Stars (树状数组)
- POJ2352 Stars(树状数组)
- 【树状数组】尝试 POJ2352-Stars
- Oracle JSON 字符串处理实例
- 1002. 写出这个数 (20)
- [POJ3415]公共子串
- css经常需要hack
- java 包的概念
- POJ2352 Stars 树状数组
- Ajax实例讲解与技术原理
- 操作系统学习笔记-程序的装载
- 新手速成APP制作
- 一个简单的读取文件的Demo
- HTTP与HTTPS
- oj2510: 存钱
- 5大移动/前端开源项目你知道几个?
- css样式的使用(三)-变形与动画(上)