本文介绍: 【代码】蓝桥OJ3694肖恩的投球游戏plus。

二维差分

#include<bits/stdc++.h>
using namespace std;

const int N = 1e3 + 5;
int a[N][N],d[N][N];

int main()
{
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1 ; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			cin >> a[i][j];
			d[i][j] = a[i][j] + a[i-1][j-1] - a[i-1][j] - a[i][j-1];
		}
	}
	while(q--)
	{
		int x1,y1,x2,y2,c;
		cin >> x1 >> y1 >> x2 >> y2 >> c;
		d[x1][y1] += c;
		d[x2 + 1][y2 + 1] += c;
		d[x1][y2 + 1] -= c;
		d[x2 + 1][y1] -= c;
	}
	for (int i = 1 ; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			a[i][j] = d[i][j] - a[i-1][j-1] + a[i-1][j] + a[i][j-1];
			cout << a[i][j] << ' ';
		}
		cout << 'n';
	}
	return 0;
}

 

原文地址:https://blog.csdn.net/2301_77138117/article/details/135854987

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_62167.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注