POJ 2352 Stars (树状数组)
来源:互联网 发布:oracle云计算产品 编辑:程序博客网 时间:2024/05/21 00:54
Stars
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 32431 Accepted: 14167
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值是按由小到大排列的,因此只需要计算[0,x]的数量,即为点的level。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <string>#include <sstream>#include <vector>#include <queue>#include <set>#include <map>#include <stack>#include <ctime>#include <fstream>using namespace std;typedef long long LL;int sum[32005];int level[32005];int lowbit(int x){return x&(-x);}int sumnum(int x){int s = 0;while(x>0){s = s + sum[x];x = x-lowbit(x);}return s;}void update(int x){while(x<32005){sum[x]++;x += lowbit(x);}}int main() {int n;//int x[32001],y[32001];while(scanf("%d",&n)!=EOF){int i = 0;memset(sum, 0, sizeof(sum)); memset(level, 0, sizeof(level)); for(i = 0;i<n;i++){int x,y;scanf("%d%d",&x,&y);level[sumnum(x+1)]++;update(x+1);//printf("%d\n",sumnum(x[i]));}for(i = 0;i<n;i++){printf("%d\n",level[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 (树状数组!!)
- Stars (poj 2352 树状数组)
- 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 2406
- mysql 报错:1130 解决方法
- FolderBrowserDialog(文件夹浏览对话框)
- 查看系统环境变量
- ASP.NET GridView 分页模板及标题定制和加序号
- POJ 2352 Stars (树状数组)
- web对象用css信息表示。在RIDE中标识对象
- 哈尔滨啤酒:策略致胜世界杯
- android数据存储的几种方式
- Windows环境下Android NDK环境搭建
- Eclipse 工具栏设置,安装STS后工具栏不能调整
- 数据库连接池 - C3P0
- Create groups for any added folders 和 Create folder references for any added folders
- poj 2907