poj 2352 Stars(线段树)
2012-08-06 16:21
155 查看
题意:给出N个星星的坐标,level[x]表示在当前节点左下方的星星的个数,然后让你输出level[0] . level[1] .....的值。星星的坐标按y的升序给出。
思路:简单线段树,每当给出一个坐标,在他所在区间就自加1,然后查到该节点,得出在左下方的星星数,就可以了。
看代码吧,
View Code
思路:简单线段树,每当给出一个坐标,在他所在区间就自加1,然后查到该节点,得出在左下方的星星数,就可以了。
看代码吧,
View Code
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> #include <algorithm> #include <queue> #include <math.h> #define N 32005 #define M 15005 using namespace std ; int p[8*N] , num[M] ; int n ; int find( int id , int pos , int ll , int rr ) { p[id]++ ; if ( pos == rr ) return p[id] - 1 ;//减去他自身 int mid = ( ll + rr ) / 2 ; if ( pos <= mid ) return find( 2*id , pos , ll , mid );//搜左子树 else return p[2*id] + find( 2*id+1 , pos , mid+1 , rr );//搜右子树,加上左子树的个数 } int main() { int i , x , y , k ; while( scanf( "%d" , &n ) != EOF ) { memset( num , 0 , sizeof( num )); memset( p , 0 , sizeof( p )); int maxx = N ; for ( i = 1 ; i <= n ; i++ ) { scanf( "%d%d" , &x , &y ); k = find( 1 , x , 0 , maxx ); //cout<<k<<endl; num[k]++ ; } //cout<<endl; for ( i = 0 ; i < n ; i++) { printf( "%d\n" , num[i] ); } } return 0 ; }
相关文章推荐
- poj 2352 Stars(简单树状数组)此题也可以用线段树来做
- POJ-2352 Stars 线段树
- POJ 2352 Stars 线段树 pascal
- POJ 2352 Stars 线段树 单点更新 成段求和
- POJ 2352 Stars Treap & 线段树
- POJ 2352 Stars (线段树)
- POJ2352 Stars(线段树 & 树状数组)
- POJ 2352 Stars - 树状数组/线段树
- POJ 2352 Stars 线段树
- poj 2352 Stars(线段树)
- poj [2352]线段树 Stars
- POJ2352_Stars(线段树/单点更新)
- poj [2352]线段树 Stars
- POJ 2352 Stars 线段树 数星星
- poj 2352 stars 线段树
- 求左下角星星之和 树状数组或线段树 poj 2352 Stars
- [POJ] 2352 Stars [线段树区间求和]
- poj 2352 && hdu 1541 Stars 线段树
- poj 2352 Stars(线段树 )
- poj 2352 Stars(线段树)