题目背景
此题约为NOIP提高组Day2T1难度。
题目描述
在 n\times nn×n 的格子上有 mm 个地毯。
给出这些地毯的信息,问每个点被多少个地毯覆盖。
输入格式
第一行,两个正整数 n,mn,m。意义如题所述。
接下来 mm 行,每行两个坐标 (x_1,y_1)(x1,y1) 和 (x_2,y_2)(x2,y2),代表一块地毯,左上角是 (x_1,y_1)(x1,y1),右下角是 (x_2,y_2)(x2,y2)。
输出格式
输出 nn 行,每行 nn 个正整数。
第 ii 行第 jj 列的正整数表示 (i,j)(i,j) 这个格子被多少个地毯覆盖。
输入输出样例
输入 #1复制
5 3 2 2 3 3 3 3 5 5 1 2 1 4
输出 #1复制
0 1 1 1 0 0 1 1 0 0 0 1 2 1 1 0 0 1 1 1 0 0 1 1 1
说明/提示
样例解释
覆盖第一个地毯后:
00 | 00 | 00 | 00 | 00 |
---|---|---|---|---|
00 | 11 | 11 | 00 | 00 |
00 | 11 | 11 | 00 | 00 |
00 | 00 | 00 | 00 | 00 |
00 | 00 | 00 | 00 | 00 |
覆盖第一、二个地毯后:
00 | 00 | 00 | 00 | 00 |
---|---|---|---|---|
00 | 11 | 11 | 00 | 00 |
00 | 11 | 22 | 11 | 11 |
00 | 00 | 11 | 11 | 11 |
00 | 00 | 11 | 11 | 11 |
覆盖所有地毯后:
00 | 11 | 11 | 11 | 00 |
---|---|---|---|---|
00 | 11 | 11 | 00 | 00 |
00 | 11 | 22 | 11 | 11 |
00 | 00 | 11 | 11 | 11 |
00 | 00 | 11 | 11 | 11 |
数据范围
对于 20\%20% 的数据,有 n\le 50n≤50,m\le 100m≤100。
对于 100\%100% 的数据,有 n,m\le 1000n,m≤1000。
上代码:
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define all(x) x.begin(),x.end()
using namespace std;
const double eps=1e-8;
const double PI=acos(-1.0);
typedef long long ll;
template<class T>int chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>int chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
#define min mmin
#define max mmax
#define abs aabs
int a[1024][1024];
int main(){
#ifdef cnyali_lk
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int n,m,xa,ya,xb,yb;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;++i){
scanf("%d%d%d%d",&xa,&ya,&xb,&yb);
++a[xa][ya];
--a[xb+1][ya];
--a[xa][yb+1];
++a[xb+1][yb+1];
}
for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)printf("%d%c",a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1],j==n?'\n':' ');
return 0;
}