二哥种花生练习

来源:互联网 发布:招行黄金分析软件 编辑:程序博客网 时间:2024/04/30 12:59

耗费大半天的时间,只写成这个样子,还有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
原创粉丝点击