POJ 2352——Stars(树状数组)
来源:互联网 发布:淘宝店铺怎么开微淘 编辑:程序博客网 时间:2024/06/06 18:47
Stars
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 32738 Accepted: 14298
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
——————————————————————分割线————————————————
题目大意:
给定n个点的坐标,按y从小到大给出,如果y相同,则按x从小到大给出。求出比(x,y)都不大于的点的个数
思路:
貌似不需要什么思路。。。。BIT
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#define ll long long#define M 32000+10using namespace std;int c[M],level[M];void update(int x,int v){ while(x<=M){ c[x]+=v; x+=x&-x; }}int getsum(int x){ int sum=0; while(x>0){ sum+=c[x]; x-=x&-x; } return sum;}int main(){ int n; scanf("%d",&n); for(int i=0;i<n;++i){ int x,y; scanf("%d %d",&x,&y); x++; level[getsum(x)]++; update(x,1); } for(int 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 (树状数组)
- 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(树状数组)
- CBCGPChartCtrl
- mfc 在同一个工程中使用多个资源文件
- 深拷贝和浅拷贝(mutableCopy和Copy)详解
- cocos2d之进度条动作CCProgressAction
- C/C++学习笔记:基础知识10
- POJ 2352——Stars(树状数组)
- poi导出excle方式二
- 调试时was自动停止解决方案
- u-boot-2010.03在tq6410上的移植详解
- HDU 1086 You can Solve a Geometry Problem too
- NanoHTTPD源码阅读
- Decode Ways 将数字转化为字母 动态规划 特殊情况处理(重)
- 深刻理解Linux进程间通信(IPC)
- Xpoded 模块开发教程