二哥种花生练习

耗费大半天的时间,只写成这个样子,还有20分没有拿到,时间超了。。。。。。。。。

下面代码,有空在研究吧。0.0

/*************************************************************************
    > File Name: test.cpp
    > Author: ma6174
    > Mail: ma6174@163.com 
    > Created Time: 2015年08月18日 星期二 14时15分16秒
 ************************************************************************/

#include<iostream>

using namespace std;

int main ()
{
	int L, W;
	cin >> L >> W;
	if (L < 1 || L > 1000 || W < 1 || W > 1000)return -1;
	int** arr = new int*[L];
	for(int x = 0; x < L; ++x) arr[x] = new int[W];
	for(int x = 0; x < L; ++x)
		for(int y = 0; y < W; ++y)
		{
			cin >> arr[x][y];
			if (arr[x][y] < 0 || arr[x][y] > 9)return -1;
		}
	int a, b;
	cin >> a >> b;
	if (a < 1 || a > L || b < 1 || b > W)return -1;

	int count = 0;
	int min = 0;
	int num;

	for(int x = 0; x < L-a+1; ++x)
		for(int y = 0; y < W-b+1; ++y)
		{
			if(y == 0 && x == 0){
			count = 0;
			for(int x_1 = 0; x_1 < a; ++x_1)
				for(int y_1 = 0; y_1 < b; ++y_1)
					count += arr[x_1+x][y_1+y];
			num = count;
			}else if (x > 0 && y == 0){
				for(int i = 0; i < b; ++i){
					num -= arr[x-1][i];
					num += arr[x+a-1][i];
				}
				count = num;
			}else{
				for(int i = x; i < x+a; ++i){
					count -= arr[i][y-1];
					count += arr[i][y+b-1];
				}
			}
			/*if ((9*a*b) == count) {
				cout << count;
				return 0;
			}*/
			if (count >= min) min = count;
		}
	cout << min;

	for(int x = 0; x < L; ++x)delete[] arr[x];
	delete[] arr;

	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值