传送门

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

这个预处理一下 $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. 2016 CCPC 长春站现场赛总结(流水账= =)

    总的来说在写这篇总结的时候心情还是愉悦的,因为第一次参加区域赛就越过铜直接拿了个银~开心之情无法用语言形容啊233= =... 从杭州坐火车到长春,去的时候24个小时,回来32个小时,在路上就花了2天 ...

  2. spark feature

    spark推测执行:当成功的Task数超过总Task数的75%(可通过参数spark.speculation.quantile设置)时,再统计所有成功的Tasks的运行时间,得到一个中位数,用这个中位 ...

  3. $\LaTeX$数学公式大全10

    $10\ Array\ environment,examples$ $\left( \begin{array}{cc} 2\tau & 7\phi-frac5{12} \\ 3\psi &am ...

  4. TCP主动打开 之 第一次握手-发送SYN

    tcp客户端与服务器端建立连接需要经过三次握手过程,本文主要分析客户端主动打开中的第一次握手部分,即客户端发送syn段到服务器端: tcp_v4_connect为发起连接主流程,首先对必要参数进行检查 ...

  5. State Threads之Co-routine的调度

    1. 相关结构体 1.1 _st_epoll_data static struct _st_epolldata { _epoll_fd_data_t *fd_data; /* 调用 epoll_wai ...

  6. Mybatis多值传递的方式

    一共有三种方式 1.参数传入Map 2参数使用@params 3.直接使用时用#{0},#{2} 参考网址 :https://www.2cto.com/database/201409/338155.h ...

  7. android canvas drawtext 字高

    Paint pFont = new Paint(); Rect rect = new Rect(); pFont.getTextBounds("豆", 0, 1, rect); L ...

  8. Cortex-M3 异常中断响应与返回

    [异常/中断响应]Cortex-M3的异常/中断响应序列包括: 入栈:把8个寄存器的值压入栈. 取向量:从向量表中找出对应的服务程序入口地址. 更新寄存器:更新堆栈指针SP,更新连接寄存器LR,更新程 ...

  9. 七十三:flask信号之信号机制和使用场景

    若安装flask是未默认安装blinker,则pip install blinker 使用信号分为3步,第一是定义一个信号,第二是监听一个信号,第三是发送一个信号 1.定义信号:定义信号需要使用到bl ...

  10. ANSI C遍历二维数组指针地址

    #include <stdio.h> int main() { ][] = {,,,}; //等价于{{1,2},{3,4}}; ; i < ; i++) { ; j < ; ...