Description
在一个大试场里,有n行m列的考生,lg和众多同学正在考试,这时,有一部分考生作弊,当然,监考老师syc能发现他们。但是只有一个监考老师,他由于高度近视,只能发现与他同行同列的作弊者,而且由于监考老师年老体弱,在考试过程中无法移动。现在已知n*m个考生中谁在作弊,请帮监考老师找一个位置,可以发现最多的作弊者(监考老师可以和某个考生在同一位置)。如果监考老师的位置上的考生在作弊,那么监考老师先前后看,发现他作弊,再左右看,又发现他作弊,算做发现2个考生作弊
Input
第一行两个数n,m ,表示试场是n*m的,接下来是n*m的矩阵,1表示作弊,0表示不作弊。
0<n,m<=100
Output
共一行,一个数,表示最多可以发现多少作弊者。
Sample Input
5 5
0 0 1 0 0
0 0 1 0 0
1 1 1 1 1
0 0 1 0 0
0 0 1 0 0
Sample Output
10
Hint
样例说明:监考老师在最中间,那个位置上的作弊者算作2次
Source
SDNU ACM-ICPC 2012 Training
#include <cstdio>
#include <iostream>
#include <cmath>
#include <
string>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long
int n, m, sum, s =
0, f[
100+
8][
100+
8];
int main()
{
scanf("%d%d", &n, &
m);
for(
int i =
0; i<n; i++
)
{
for(
int j =
0; j<m; j++
)
{
scanf("%d", &
f[i][j]);
}
}
for(
int i =
0; i<n; i++
)
{
for(
int j =
0; j<m; j++)
//一个一个滴搜索鸭
{
int miao = n-
1, ying = m-
1;
sum =
0;
for(; ying >=
0; ying--)
//行
{
if(f[i][ying])sum++
;
}
for(; miao >=
0; miao--)
//列
{
if(f[miao][j])sum++
;
}
if(sum>s)s =
sum;
}
}
printf("%d\n", s);
return 0;
}
转载于:https://www.cnblogs.com/RootVount/p/10889726.html