码迷,mamicode.com
首页 > 其他好文 > 详细

poj 2352 Stars

时间:2014-07-21 13:38:26      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:os   io   for   re   c   ar   

题意就是一颗星星的左下方有多少颗星星就是几级;

把每级的星星个数统计好输出就ok;

但不能用二维树状数组,会超内存,,


#include<stdio.h>
#include<string.h>
#include<iostream>
#define maxn 32001
using namespace std;
int a;
int arr[maxn];
int low(int x)
{
    return x&(-x);
}
void update(int x,int val)
{
    for(int i=x;i<=maxn;i+=i&-i)
        arr[i]+=val;
}
int getsun(int x)
{
    int temp=0;
    while(x>0)
    {
        temp+=arr[x];
        x-=low(x);
    }
    return temp;
}
int main()
{
    int stars[maxn];
    memset(stars,0,sizeof(stars));
    scanf("%d",&a);
    memset(arr,0,sizeof(arr));
    for(int i=1;i<=a;i++)
    {
        int x,y;;
        scanf("%d %d",&x,&y);
        int level=getsun(x+1);
        stars[level]++;
        update(x+1,1);
    }
    for(int i=0;i<a;i++)
        printf("%d\n",stars[i]);
    return 0;
}


poj 2352 Stars,布布扣,bubuko.com

poj 2352 Stars

标签:os   io   for   re   c   ar   

原文地址:http://blog.csdn.net/asuxiexie/article/details/38010097

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!