看看哪里错了

P3397 地毯

cht3362733140 @ 2024-10-12 21:25:11

#include<stdio.h> 
int a[1000][1000];
int main()
{
    int i,m,n,x1,x2,y1,y2,j,b,c;
    scanf("%d %d",&n,&m);
    for( i=0;i<n;i++)
    {
        for( j=0;j<n;j++)
       a[i][j] = 0;
    }
    for(i=0;i<m;i++)  
    {  
    scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
     for(b=x1;b<x2;b++)
        {
            for(c=y1;c<y2;c++)
            {
                a[b][c]++;
            }
        } 
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {   
        printf("%d ",a[i][j]);  
        }
        printf("\n");
    }  
    return 0;
}

by zzz13579zzz @ 2024-10-12 21:29:20

样例都没过吧


by cht3362733140 @ 2024-10-12 21:30:18

@zzz13579zzz 哪里问题


by AstaSunch_ @ 2024-10-12 21:31:23

@cht3362733140 你这算法复杂度都不对啊


by zzz13579zzz @ 2024-10-12 21:31:27

左上角(1,1),而且遍历是[x1,x2]


by AstaSunch_ @ 2024-10-12 21:31:53

@cht3362733140 人家让你用二维前缀和你暴力枚举


by cht3362733140 @ 2024-10-12 21:35:55

@AstaSunch_ 所以怎么改


by AstaSunch_ @ 2024-10-12 21:39:05

@cht3362733140 你自己去学前缀和啊,很简单的


|