80分,求改#1,#2WA

P3397 地毯

a1234a @ 2024-12-18 16:30:32

#include <bits/stdc++.h>
using namespace std;
long long a[1005][1005];
long long n, m, x, y, x2,y2;
int main()
{
    cin >> n >> m;
    while (n--){
        cin >> x >> y >> x2 >> y2;
        for (int i = x; i <= x2; i++)
            a[i][y]++, a[i][y2 + 1]--;
    }
    for (int i = 1; i <= m; i++){
        for (int j = 1; j <= m; j++){
            a[i][j] += a[i][j - 1];
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

by tsgaoyunxuan @ 2025-01-06 21:56:46

@a1234a,你把你while循环的n--改成m-- 因为他是循环输入M组数据,所以要循环M次 我的代码送给你

#include<bits/stdc++.h>
using namespace std;
long long a[1011][1011],x,y,xx,yy;
int main(){
    long long n,m;
    cin>>n>>m;
    for(long long i=1;i<=m;i++){
        cin>>x>>y>>xx>>yy;
        for(long long i=x;i<=xx;i++){
            for(long long j=y;j<=yy;j++){
                a[i][j]++;
            }
        }
    }
    for(long long i=1;i<=n;i++){
        for(long long j=1;j<=n;j++){
            cout<<a[i][j]<<' ';
        }
        cout<<endl;
    }
    return 0;
}

by a1234a @ 2025-01-11 15:11:33

@tsgaoyunxuan 谢谢 求互关


|