P3397 地毯

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
这道题暴力其实也可以过,但是最好不要暴力了,能过都是运气而已,正经做法用差分。二维差分来做,不知道的差分的去康康其他dalao的博客~

#include <iostream>
#include <cstring>
using namespace std;
#define Max 1005
int a[Max][Max];
int c[Max][Max];
    int main()
    {
        memset(a,0, sizeof(a));
        memset(c,0, sizeof(c));
        int n,m,x1,x2,y1,y2;
        cin>>n>>m;
        for(int i=1;i<=m;i++)
        {
            cin>>x1>>y1>>x2>>y2;
            c[x1][y1]+=1;
            c[x2+1][y2+1]+=1;
            c[x2+1][y1]-=1;
            c[x1][y2+1]-=1;
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                c[i][j]=c[i][j]+c[i-1][j]+c[i][j-1]-c[i-1][j-1];
                a[i][j]+=c[i][j];
                cout<<a[i][j]<<" ";
            }
            cout<<endl;
        }
        return 0;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值