## 没有超时或溢出
by oistr @ 2019-06-01 22:22:07
## 重发一个带解释的
```
#include <cstdio>
#include <algorithm>
#include <cmath>
char f[55][55];
using namespace std;
int cou(int w,int b,int r,int n,int m)
{
int wc=0,bc=0,rc=0;
int count=0;
for(int i=1;i<=n;i++)
{
if(wc!=w)//当该涂W色时
{
for(int j=1;j<=m;j++)
{
if(f[i][j]!='W')//计数
{
count++;
//printf("w%d#%d:%d %d\t%c-W\n",wc+1,count,i,j,f[i][j]);
}
}
wc++;
}
//挨个判断,计数
else if(wc==w&&bc!=b)
{
for(int j=1;j<=m;j++)
{
if(f[i][j]!='B')
{
count++;
//printf("b%d#%d:%d %d\t%c-B\n",bc+1,count,i,j,f[i][j]);
}
}
bc++;
}
//同上
else if(wc==w&&bc==b&&rc!=r)
{
for(int j=1;j<=m;j++)
{
if(f[i][j]!='R')
{
count++;
//printf("r%d#%d:%d %d\t%c-R\n",rc+1,count,i,j,f[i][j]);
}
}
rc++;
}
}
return count;
}
int main()
{
int n,m;
char temp;
int ans=pow(10,9);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%c",&temp);//读入换行符
for(int j=1;j<=m;j++)
{
scanf("%c",&f[i][j]);//读入字符
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i+j>=n)//枚举每种情况
{
continue;
}
int k=n-i-j;//计算出涂R色的行数
//printf("$$$Case:%d %d %d %d\n---------------------\n",i,j,k,cou(i,j,k,n,m));
ans=min(cou(i,j,k,n,m),ans);//与之前最小的比较
}
}
printf("%d",ans);//输出
return 0;
}
```
by oistr @ 2019-06-01 22:25:57
# ?????
by oistr @ 2019-06-01 22:27:06
```cpp
#include <cstdio>
int main() {puts("11");}
```
~~样例过了呀,怎么就WA了呢?~~
by Kubic @ 2019-06-01 22:42:46
@[zxp_oistream](/space/show?uid=180720)
不愧是刚学OI的人,过样例并不代表着你的代码是正确的。
by Leap_Frog @ 2019-06-01 23:05:46
@[小跳蛙](/space/show?uid=44805)
by oistr @ 2019-06-02 15:41:13
~~英语老师:不愧是学OI的,阅读理解能力堪忧啊。。。~~
# 我不是那个意思,这道题下载不了数据,我是求教这个代码哪里有错
by oistr @ 2019-06-02 15:43:24
@[Kubic](/space/show?uid=119621) 请您认真一点
by oistr @ 2019-06-02 15:44:01
那么这道题的样例很毒?(~~像某些题目的样例一样,错误代码都能过~~)
by oistr @ 2019-06-02 15:47:44
@[zxp_oistream](/space/show?uid=180720) 难道不应该是大部分题都这样吗
by Kubic @ 2019-06-02 19:58:20