救救救救救!!!!!!!!!

P3397 地毯

AriesWhite_Yan @ 2024-10-16 16:55:13

#include <iostream>
using namespace std;
int a[2000][2000];

int main()
{
    int n , m , x1 , y1 , x2 , y22;
    cin >> n >> m;
    while(m--)
    {
        cin >> x1 >> y1 >> x2 >> y22;
        for(int i = x1 ; i <= x2 ; i++)
        {
            a[i][y1] = 1;
            a[i][y22+1] = -1;
        }
    }
    for(int i = 1 ; i <= n+5 ; i++)
    {
        for(int j = 1 ; j <= n+5 ; j++)
        {
            a[i][j] += a[i][j-1];
        }
    }
    for(int i = 1 ; i <= n ; i++)
    {
        for(int j = 1 ; j <= n ; j++)
        {
            if(j != n){cout << a[i][j] << " ";}
            else{cout << a[i][j];}
        }
        if(i != n){cout << endl;}
    }
}

by HEzzz @ 2024-10-16 17:01:14

@AriesWhite_Yan

应该是

a[i][y1]+=1;
a[i][y22+1]-=1;

by AriesWhite_Yan @ 2024-10-16 17:04:56

@HEzzz 原来错在这没注意到,谢谢!


by HEzzz @ 2024-10-16 17:06:19

@AriesWhite_Yan 求关


|