【POJ2352】【树状数组】Stars
Description

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
Output
Sample Input
5
1 1
5 1
7 1
3 3
5 5
Sample Output
1
2
1
1
0
Hint
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <utility>
#include <iomanip>
#include <string>
#include <cmath>
#include <map> const int MAXN = + ;
const int MAX = + ;
using namespace std;
struct DATA{
int x, y;
bool operator < (const DATA &b)const{
if (y == b.y) return x < b.x;
return y < b.y;
}
}data[MAXN];
int n, level[MAXN];
int C[MAX]; void init(){
memset(C, , sizeof(C));
scanf("%d", &n);
for (int i = ; i <= n; i++){
scanf("%d%d", &data[i].x, &data[i].y);
}
sort(data + , data + + n);
}
int lowbit(int x){return x & -x;}
void add(int x){
while (x <= ){
C[x]++;
x += lowbit(x);
}
}
int sum(int x){
int cnt = ;
while (x > ){
cnt += C[x];
x -= lowbit(x);
}
return cnt;
}
void work(){
memset(level, , sizeof(level));
for (int i = ; i <= n; i++){
level[sum(data[i].x + )]++;
add(data[i].x + );
}
for (int i = ; i < n; i++) printf("%d\n", level[i]);
} int main(){
#ifdef LOCAL
freopen("data.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
init();
work();
return ;
}
【POJ2352】【树状数组】Stars的更多相关文章
- poj2352树状数组
Astronomers often examine star maps where stars are represented by points on a plane and each star h ...
- [ACM_数据结构] POJ2352 [树状数组稍微变形]
Description Astronomers often examine star maps where stars are represented by points on a plane and ...
- poj2352树状数组解决偏序问题
树状数组解决这种偏序问题是很厉害的! /* 输入按照y递增,对于第i颗星星,它的level就是之前出现过的星星中,横坐标小于i的总数 */ #include<iostream> #incl ...
- hdu 1541 (基本树状数组) Stars
题目http://acm.hdu.edu.cn/showproblem.php?pid=1541 n个星星的坐标,问在某个点左边(横坐标和纵坐标不大于该点)的点的个数有多少个,输出n行,每行有一个数字 ...
- POJ-2352 Stars 树状数组
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description A ...
- poj2352 Stars【树状数组】
Astronomers often examine star maps where stars are represented by points on a plane and each star h ...
- 【二维偏序】【树状数组】【权值分块】【分块】poj2352 Stars
经典问题:二维偏序.给定平面中的n个点,求每个点左下方的点的个数. 因为 所有点已经以y为第一关键字,x为第二关键字排好序,所以我们按读入顺序处理,仅仅需要计算x坐标小于<=某个点的点有多少个就 ...
- POJ 2352 Stars(树状数组)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30496 Accepted: 13316 Descripti ...
- hdu 1541/poj 2352:Stars(树状数组,经典题)
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- Stars(树状数组或线段树)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37323 Accepted: 16278 Description A ...
随机推荐
- soundtouch源码分析__based on csdn :
1. soundtouch介绍和相关资源 The SoundTouch Library Copyright © Olli Parviainen 2001-2014 SoundTouch is an o ...
- ant 学习与开发
ant 学习与开发 http://www.blogjava.net/amigoxie/archive/2007/11/09/159413.html
- Objective-c知识小结
1.创建一个类产生.h和.m两个文件,.h中对用到的变量.方法作声明,.m文件中实现,导入时只导入.h文件,如果直接把方法写在.m文件中,未在.h文件中进行声明,则是私有方法 2.@interfac ...
- HDOJ/HDU 2562 奇偶位互换(交换位置~)
Problem Description 给定一个长度为偶数位的0,1字符串,请编程实现串的奇偶位互换. Input 输入包含多组测试数据: 输入的第一行是一个整数C,表示有C测试数据: 接下来是C组测 ...
- Myriad2 简介
本文翻译自英文: Myriad2图像处理器是一个永远在线的移动视觉处理器系统.它提供了非常强处理能力和及其高效了内存带宽以满足计算机视觉和计算成像应用的需求. Myriad2同时也满足移动设备的非常低 ...
- asterisk 能打电话的配置
若使用的是chan_sip.so模块,则在sip.conf里添加: [10]type=friend;context=phonescontext=publichost=dynamicsecret=123 ...
- 各种Markdown处理器的列表
从MarkdownImplementations - Markdown Community Group可以找到一个实现markdown处理器的列表,如下: Name Language Type Des ...
- C#截取指定字符串函数
本文转载:http://www.cnblogs.com/liufei88866/archive/2012/05/12/2497395.html 一.通过函数方式进行获取. public string ...
- JAVA LinkedList和ArrayList的使用及性能分析
第1部分 List概括List的框架图List 是一个接口,它继承于Collection的接口.它代表着有序的队列.AbstractList 是一个抽象类,它继承于AbstractCollection ...
- tcpdump抓包以及port查看的一些操作
1.tcpdump. nginx开启后会占用80端口,此时运行命令:tcpdump tcp port 80 结果例如以下: [syswj@host ~]$ sudo tcpdump tcp port ...