markdown 在线制作ppt json校验和格式化工具

POJ 1195

#include <iostream>
#define MAXN 1100
using namespace std;

long _m[MAXN][MAXN];//C数组

int n;

void init();
long Lowbit(int t);
long sum_b_e(int x,int y);
void plus(int x,int y,long num);
long give_place(int i,int j);
long square;

int main()
{
    //freopen("acm.acm","r",stdin);
    int num_0;
    int i;
    int j;
    int x;
    int y;
    int _x;
    int _y;
    int a;
    int _b;
    int _e;
    int ins;
    scanf("%d",&num_0);
    scanf("%d",&square);
    n = square;
    while(scanf("%d",&ins))
    {
        if(ins == 1)
        {
            scanf("%d%d%d",&x,&y,&a);
            ++ x;
            ++ y;

            plus(x,y,a);
        }
        else if(ins == 2)
        {
            scanf("%d%d%d%d",&x,&y,&_x,&_y);
            ++ x;
            ++ y;
            ++_x;
            ++_y;
            cout<<sum_b_e(_x,_y) + sum_b_e(x-1,y-1) - sum_b_e(_x,y-1) - sum_b_e(x-1,_y)<<endl;
        }
        else if(ins == 3)
        {
            break;
        }
    }
    
}


long Lowbit(int t) 
{ 
    return t & (t^(t - 1)); 
}


long sum_b_e(int x,int y) 
{ 
    long sum = 0; 
    int i;
    int j;
    for(i = x; i >= 1; i -= Lowbit(i))
    {
        for(j = y; j >= 1; j -= Lowbit(j))
        { 
            sum += _m[i][j];
        }
    } 
    return sum; 
}

void plus(int x,int y,long num) 
{ 
    int i;
    int j;
    for(i = x; i <= n; i += Lowbit(i))
    {
        for(j = y; j <= n; j += Lowbit(j))
        { 
             _m[i][j] += num; 
        } 
    }
} 

 

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。 

技术网站地址: vmfor.com

posted @ 2015-06-09 13:49  GavinHacker  阅读(130)  评论(0编辑  收藏  举报
markdown 在线制作ppt json校验和格式化工具