EOJ2020.7C 二维前缀和+差分

C题
题意:给你一个nm的矩阵,然后让你求出一个ab的矩阵,其中nm的矩阵表示对该单位的贡献,在ab的矩阵上移动,最后得到的为x100/max(x)。
思路:二维前缀和和差分维护每一个点对a
b矩阵的贡献即可。

#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define per(i, a, n) for(int i = n; i >= a; i--)
#define IOS std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define fopen freopen("file.in","r",stdin);freopen("file.out","w",stdout);
#define fclose fclose(stdin);fclose(stdout);
const int inf = 1e9;
const ll onf = 1e18;
const int maxn = 1e5+10;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-48;ch=getchar();}
	return x*f;
}
int dp[3845][2165];
signed main(){
	int n=read(), m=read(), a=read(), b=read();
	rep(i,1,n){
		rep(j,1,m){
			int x = read();
			if(x){
				dp[i][j] += 1;
				dp[i][b-m+1+j] -= 1;
				dp[a-n+1+i][j] -= 1;
				dp[a-n+1+i][b-m+1+j] += 1;
			}
		}
	}
	int mx = 0;
	rep(i,1,a){
		rep(j,1,b){
			dp[i][j] = dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+dp[i][j], mx = max(mx, dp[i][j]);
		}
	}
	rep(i,1,a){
		rep(j,1,b){
			printf("%d ", dp[i][j]*100/mx);
		}
		printf("\n");
	}
	return 0;
}

你可能感兴趣的:(思维题)