标签:地方 sizeof ble 二维 imp bit ++ def load
模板:
ditu[x1][y1]++;
ditu[x2+1][y1]--;
ditu[x1][y2+1]--;
ditu[x2+1][y2+1]++;
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++)
dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+ditu[i][j];
题目:
思路:
给你了n,m的布偶矩阵,每个 1 点对应在a,b矩阵可以触及的地方,用差分存。
二维前缀和模板一套
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define il inline
#define it register int
#define inf 0x3f3f3f3f
#define lowbit(x) (x)&(-x)
#define pii pair<int,int>
#define mak(n,m) make_pair(n,m)
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 998244353
#define ios ios::sync_with_stdio(false)
const int maxn=4e3+10;
ll ksm(ll a,ll b){if(b<0)return 0;ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod;b>>=1;}return ans;}
const double pi=acos(-1.0);
int n,m,a,b;
int t[maxn][maxn],dp[maxn][maxn],ditu[maxn][maxn],a1[maxn][maxn];
int main(){
scanf("%d%d%d%d",&n,&m,&a,&b);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("%d",&t[i][j]);
if(t[i][j]){
int x1=i,x2=a-(n-i),y1=j,y2=b-(m-j);
//cout<<y1<<y2<<x1<<x2<<endl;
if(x1>x2){swap(x1,x2);}
if(y1>y2){swap(y1,y2);}
ditu[x1][y1]++;
ditu[x2+1][y1]--;
ditu[x1][y2+1]--;
ditu[x2+1][y2+1]++;
}
}
}
int maxx=-1;
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++)
dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+ditu[i][j];
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++){
maxx=max(dp[i][j],maxx);
}
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++){
printf(j==b?"%d\n":"%d ",dp[i][j]*100/maxx);
}
return 0;
}
之前就会的,就是没有模板,索性就整一个,刚好又做到这种题型的模板
EOJ Monthly 2020.7 Sponsored by TuSimpleC题(二维前缀和)
标签:地方 sizeof ble 二维 imp bit ++ def load
原文地址:https://www.cnblogs.com/luoyugongxi/p/13339426.html