文章
10
粉丝
165
获赞
7
访问
26.4k
可以利用尺取法解决这个问题
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define MAX 102
int matrix[MAX][MAX];
int tr[MAX];
int merge(int n, int goal) {
int ans = -1;
int start = 0, end = 0, sum = 0;
while (end < n) {
if (sum < goal)
sum += tr[end];
while (sum >= goal) {
int len = end - start + 1;
if (ans == -1) ans = len;
else if (len < ans) ans = len;
sum -= tr[start++];
}
++end;
}
return ans;
}
int main(int argc, char const *argv[])
{
int n, m, k;
while(scanf("%d %d %d",&n, &m, &k) != EOF) {
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
scanf("%d",&matrix[i][j]);
}
}
int ans = n*m + 1;
for(int i = 0; i < m; i++) {
memset(tr,0,sizeof(tr));
for(int ...
登录后发布评论
暂无评论,来抢沙发