zkccjdl @ 2024-11-05 20:35:32
#include<bits/stdc++.h>
using namespace std;
int a[15][15];
bool check(int x1,int x2,int y1,int y2){
int b[2] = {0,0};
for(int i = x1;i <= x2;i++){
for(int j = y1;j <= y2;j++){
b[a[i][j]] ++;
}
}
return b[0] == b[1];
}
int main(){
int n,m;
cin >> n >> m;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++){
cin >> a[i][j];
}
}
int ans = 0;
for(int i = 1;i <= n;i++){
for(int j= 1;j <= m;i++){
for(int ii = i;ii <= n;i++){
for(int jj = j;jj <= m;j++){
if(check(i,ii,j,jj)){
ans = max(ans,(ii-i+1) * (jj-j + 1));
}
}
}
}
}
cout << ans;
return 0;
}
by tengyuxuan @ 2024-11-26 16:42:10
@zkccjdlmain中第三层和第四层循环是ii++,jj++, 而不是i++j++
by tengyuxuan @ 2024-11-26 16:46:41
改完还是零分 给你看看我的代码:
#include <bits/stdc++.h>
using namespace std;
char a[102][102];
bool zx(int stx,int sty,int x,int y){
int bsum=0,hsum=0;
for(int i=stx;i<=x;i++){
for(int j=sty;j<=y;j++){
if(a[i][j]=='0')bsum++;
if(a[i][j]=='1')hsum++;
}
}
if(bsum==hsum)return 1;
return 0;
}
int main(){
int maxn=0;
bool f=0;
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
for(int k=i;k<=n;k++){
for(int v=j;v<=m;v++){
if((k-i+1)*(v-j+1)>maxn&&zx(i,j,k,v)){
maxn=(k-i+1)*(v-j+1);
}
}
}
}
}
cout<<maxn;
return 0;
}
by tengyuxuan @ 2024-11-26 16:51:38
int a[15][15] 改成char a[15][15]
by tengyuxuan @ 2024-11-26 16:55:05
该你改完了
#include<bits/stdc++.h>
using namespace std;
int改成char a[15][15];
bool check(int x1,int x2,int y1,int y2){
int b[2] = {0,0};
for(int i = x1;i <= x2;i++){
for(int j = y1;j <= y2;j++){
b[(a[i][j]-48)] ++;
}
}
return b[0] == b[1];
}
int main(){
int n,m;
cin >> n >> m;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++){
cin >> a[i][j];
}
}
int ans = 0;
for(int i = 1;i <= n;i++){
for(int j= 1;j <= m;i++改为j++){
for(int ii = i;ii <= n;i++改为ii++){
for(int jj = j;jj <= m;j++改为jj++){
if(check(i,ii,j,jj)&&ans<(ii-i+1) * (jj-j + 1)){
ans = (ii-i+1) * (jj-j + 1);
}
}
}
}
}
cout << ans;
return 0;
}
by tengyuxuan @ 2024-11-26 16:55:32
@zkccjdl
by tengyuxuan @ 2024-11-26 17:01:29
下次抄题解细心点互关