B. Yet Another Crosses Problem

在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述
//读题真的很重要,现在英语太差了吧,都看不懂题,哭了,打cf的时候,B题的题意愣是没懂
http://codeforces.com/contest/1194/problem/B
//后来看了下别人写的,555
//理解了一下题意其实很简单,就是找缺少黑色最少的行列

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
const int maxn=5e4+5;
//记得要开string的数组,开不了char的二维数组
string str[maxn];
//把行和列分成两个数组,就不会有问题
int h[maxn],l[maxn];//计算每行每列有多少白的
const int inf=0x3f3f3f;
int main()
{
    int t,n,m;
    scanf("%d",&t);
    while(t--)
    {
        memset(h,0,sizeof(h));
        memset(l,0,sizeof(l));
        scanf("%d%d",&n,&m);
        for(int i=0;i<n;i++)
        cin>>str[i];
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(str[i][j]=='.')
                h[i]++;
            }
        }
        for(int j=0;j<m;j++)
        {
            for(int i=0;i<n;i++)
            {
                if(str[i][j]=='.')
                l[j]++;
            }
        }
        int ans=0,minn=inf;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(str[i][j]=='.')
                ans=-1;
                else
                ans=0;
                if(h[i]+l[j]+ans<minn)
                minn=h[i]+l[j]+ans;

            }
        }
        printf("%d\n",minn);
    }
    return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值