HDU_1541 Stars(树状数组)
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                HDU_1541 Stars(树状数组)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.                        
                                poj上1A, HDU上6A,我暈啊!注意幾點(diǎn):
1、多組數(shù)據(jù);
2、memset(c, 0, siezeof(c));
3、memset(ans, 0, sizeof(ans));
my code:
View Code #include <stdio.h>#include <string.h>
#define N 32010
int c[N], n, ans[N];
int lowbit(int i)
{
return i&(-i);
}
void add(int i, int val)
{
while(i <= N)
{
c[i] += val;
i += lowbit(i);
}
}
int sum(int i)
{
int s = 0;
while(i > 0)
{
s += c[i];
i -= lowbit(i);
}
return s;
}
int main()
{
int i, x, y;
//freopen("data.in", "r", stdin);
while(~scanf("%d", &n))
{
memset(ans, 0, sizeof(ans));
memset(c, 0, sizeof(c));
for(i = 0; i < n; i++)
{
scanf("%d%d", &x, &y);
ans[sum(x+1)]++;
add(x+1, 1);
}
for(i = 0; i < n; i++)
printf("%d\n", ans[i]);
}
return 0;
}
轉(zhuǎn)載于:https://www.cnblogs.com/vongang/archive/2011/08/15/2139580.html
總結(jié)
以上是生活随笔為你收集整理的HDU_1541 Stars(树状数组)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
 
                            
                        - 上一篇: android 学习查阅笔记
- 下一篇: zoj2271 Chance to En
