在n * n的格子上有m个地毯。给出这些地毯的信息,问每个点被多少个地毯覆盖。
二维拆分,将一维拆分的思路一层一层的用到二维的每一层上。
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=3e5+5;
const int mod=998244353;
const int inf=0x7fffffff;
const double pi=3.1415926535;
using namespace std;
int arr[2000][2000];
signed main()
{
int n,m,x1,y1,x2,y2;
cin>>n>>m;
for(int j=0;j<m;j++)
{
cin>>x1>>y1>>x2>>y2;
for(int i=x1;i<=x2;i++)
{
arr[i][y1]++;
arr[i][y2+1]--;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
arr[i][j]+=arr[i][j-1];
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
本文地址:https://blog.csdn.net/ACkingdom/article/details/107168158
如对本文有疑问, 点击进行留言回复!!
M - Jamie‘s Contact Groups POJ - 2289(二分 + 多重匹配)
H - Antenna Placement POJ - 3020(最小边覆盖)
Unity组件【Camera && Flare Layer】
K - Treasure Exploration POJ - 2594
网友评论