传送门

直接枚举填满哪一行,然后看看这一行填满以后哪一列最小

这个预处理一下 $cnt[i]$ 表示初始时第 $i$ 列有几个位置填满就可以做到 $O(m)$

对于所有情况取个 $min$ 就是答案,复杂度 $O(nm)$

存输入用 $string$ 即可,多组数据记得清空

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=4e5+;
const int INF=1e9+;
int Q,n,m,cnt[N],ans;
string s[N];
int main()
{
Q=read();
while(Q--)
{
for(int i=;i<=n;i++) s[i].clear();
for(int i=;i<m;i++) cnt[i]=;
n=read(),m=read(); ans=INF;
for(int i=;i<=n;i++)
{
cin>>s[i];
for(int j=;j<m;j++) cnt[j]+=s[i][j]=='*';
}
for(int i=;i<=n;i++)
{
int tot=; for(int j=;j<m;j++) tot+=s[i][j]=='*';
for(int j=;j<m;j++) ans=min(ans, m-tot+ n-(cnt[j]+(s[i][j]!='*')) );
}
printf("%d\n",ans);
}
return ;
}

Codeforces 1194B. Yet Another Crosses Problem的更多相关文章

  1. Codeforces - 1194B - Yet Another Crosses Problem - 水题

    https://codeforc.es/contest/1194/problem/B 好像也没什么思维,就是一个水题,不过蛮有趣的.意思是找缺黑色最少的行列十字.用O(n)的空间预处理掉一维,然后用O ...

  2. B. Yet Another Crosses Problem

    B. Yet Another Crosses Problem time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  3. Codeforces Round #425 (Div. 2) Problem A Sasha and Sticks (Codeforces 832A)

    It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day h ...

  4. 【codeforces 442B】 Andrey and Problem

    http://codeforces.com/problemset/problem/442/B (题目链接) 题意 n个人,每个人有p[i]的概率出一道题.问如何选择其中s个人使得这些人正好只出1道题的 ...

  5. Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律

    Another Rock-Paper-Scissors Problem 题目连接: http://codeforces.com/gym/100015/attachments Description S ...

  6. 屏蔽Codeforces做题时的Problem tags提示

    当在Codeforces上做题的时,有时会无意撇到右侧的Problem tags边栏,但是原本并不希望能够看到它. 能否把它屏蔽了呢?答案是显然的,我们只需要加一段很短的CSS即可. span.tag ...

  7. codeforces#253 D - Andrey and Problem里的数学知识

    这道题是这种,给主人公一堆事件的成功概率,他仅仅想恰好成功一件. 于是,问题来了,他要选择哪些事件去做,才干使他的想法实现的概率最大. 我的第一个想法是枚举,枚举的话我想到用dfs,但是认为太麻烦. ...

  8. Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读

    http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...

  9. Codeforces 803 G. Periodic RMQ Problem

    题目链接:http://codeforces.com/problemset/problem/803/G 大致就是线段树动态开节点. 然后考虑到如果一个点还没有出现过,那么这个点显然未被修改,就将这个点 ...

随机推荐

  1. Linux 相关系统日志查看

    1. 登录日志 cat /var/log/secure 涉及到账号登录的日志信息都会记录在此文件中. 2. Unit 的启动日志 journalctl 可以查看所有 unit 的启动日志,日志的配置文 ...

  2. TCP层shutdown系统调用的实现分析

    概述 shutdown系统调用在tcp层会调用两个函数,对于ESTABLISHED状态需要调用tcp_shutdown关闭连接,对于LISTEN和SYN_SENT状态则需要以非阻塞模式调用tcp_di ...

  3. 安装指定版本的Ionic或Cordova

    安装ionic 及 cordova npm install -g cordova ionic更新命令 npm update -g cordova ionic安装特定版本 npm install -g ...

  4. ssh 远程登录错误

    错误信息: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: REMOTE HOST IDENTIFICATI ...

  5. python pandas(ix & iloc &loc)

    python pandas(ix & iloc &loc) loc——通过行标签索引行数据 iloc——通过行号索引行数据 ix——通过行标签或者行号索引行数据(基于loc和iloc ...

  6. ThinkPhp中验证码不显示和配置项的问题解决方法

    1.验证码不显示在调用验证码之前加上 ob_clean();像这样: public function verify(){ ob_clean(); $verify = new \Think\Verify ...

  7. jxbrowser 实现java 和 js互相调用

    https://blog.csdn.net/shuaizai88/article/details/73743626 今天我们使用jxbrowser  实现js直接调用java代码. 调用javaTes ...

  8. TypeScript 编译目标(target)设置

    TypeScript的编译配置文件tsconfig.json中有许多配置项,本文简单对比编译目标环境的配置项(target)的设置.模块(module)不在本文讨论之内,是另外一个大话题. 实验对于t ...

  9. 最短路径:Dijkstra算法 C#

    class Program { ; static void Main(string[] args) { Console.WriteLine("各点距离矩阵如下:"); Consol ...

  10. padding的计算方法

    转自https://blog.csdn.net/qq_34599526/article/details/83755275 VALID:如果卷积核超出特征层,就不再就计算,即卷积核右边界不超出Featu ...