Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

因为数组大小不知道,我每次计算到1025,不然就WA,为什么????

Posted by zzzjjjjjj at 2011-10-10 22:17:14 on Problem 1195
#include <cstdio>
#include <iostream>
using namespace    std;


int s,c[1029][1029];


int lowbit(int x)
{
    return x&(-x);
}

void modif(int x,int y,int val )
{
    int i,j;

    for(i=x;  i<=1029;  i+=lowbit(i) )
    for(j=y;  j<=1029;  j+=lowbit(j) )
    c[i][j] += val;
}

int getsum(int x, int y)
{
   int i, j, ans=0;

   for(i=x;  i>0;  i-=lowbit(i) )
   for(j=y;  j>0;  j-=lowbit(j) )
   ans += c[i][j];

   return ans;
}

int main()
{
    int  t , i , j , s , x , y , xx ,yy , p , w;


    while( scanf("%d",&t) != EOF )
    {
            if( t==0 )
            {
                scanf("%d", &s);
                for(i=0;  i<=s;  i++ )
                for(j=0;  j<=i;  j++ )
                c[i][j] = c[j][i] = 0;
                continue;
            }

            if( t==1 )
            {
                scanf("%d%d%d", &x, &y, &p);
                x++; y++;
                modif(x, y, p);
                continue;
            }

            if( t==2 )
            {
                scanf("%d%d%d%d", &x, &y,  &xx, &yy);
                x++;  y++;
                xx++; yy++;
                w = getsum(xx,yy) - getsum(x-1,yy) - getsum(xx,y-1) + getsum(x-1,y-1);
                printf("%d\n",w);
                continue;
            }

            if( t==3 )
                return 0;

            else
                return 0;
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator