zoukankan      html  css  js  c++  java
  • HDU_1541 Stars(树状数组)

      poj上1A, HDU上6A,我晕啊!注意几点:

    1、多组数据;

    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;
    }
  • 相关阅读:
    poj 3669 Meteor Shower
    poj 3232 Accelerator
    poj 2155 Matrix
    poj 3628 Bookshelf 2
    cf C. Maze
    cf B. Fox Dividing Cheese
    hdu Children’s Queue
    cf D. Broken Monitor
    cf C. Mittens
    cf B. Berland Bingo
  • 原文地址:https://www.cnblogs.com/vongang/p/2139580.html
Copyright © 2011-2022 走看看