Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴一下,诸位给点优化建议

Posted by ilbn20 at 2016-05-11 14:19:48 on Problem 1050
#include <iostream>
using namespace std;
int map[110][110];
int sum[110][110];
int getsum(int w, int x, int y, int z) {
	return sum[y][z] + sum[w - 1][x - 1] - sum[w - 1][z] - sum[y][x - 1];
}
int main() {
	int ans = -100000;
	int m;
	cin >> m;
	for(int i = 1; i <= m; i++)
		for (int j = 1; j <= m; j++) 
		{
			cin >> map[i][j];
			sum[i][j] = map[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
		}
	for(int i=1;i<=m;i++)
		for (int j = i; j <= m; j++) {
			int ttt = 0;
			for (int t = 1; t <= m; t++) {
				if (ttt > 0)
					ttt += getsum(i, t, j, t);
				else ttt = getsum(i, t, j, t);
				if (ttt > ans) ans = ttt;
			}
		}
	cout << ans << endl;
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator