time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a picture consisting of n

rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m

from the left to the right. Each cell is painted either black or white.

You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers x

and y, where 1≤x≤n and 1≤y≤m, such that all cells in row x and all cells in column y

are painted black.

For examples, each of these pictures contain crosses:

The fourth picture contains 4 crosses: at (1,3)

, (1,5), (3,3) and (3,5)

.

Following images don't contain crosses:

You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.

What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?

You are also asked to answer multiple independent queries.

Input

The first line contains an integer q

(1≤q≤5⋅104

) — the number of queries.

The first line of each query contains two integers n

and m (1≤n,m≤5⋅104, n⋅m≤4⋅105

) — the number of rows and the number of columns in the picture.

Each of the next n

lines contains m

characters — '.' if the cell is painted white and '*' if the cell is painted black.

It is guaranteed that ∑n≤5⋅104

and ∑n⋅m≤4⋅105

.

Output

Print q

lines, the i-th line should contain a single integer — the answer to the i

-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.

Example
Input

Copy
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
Output

Copy
0
0
0
0
0
4
1
1
2
Note

The example contains all the pictures from above in the same order.

The first 5 pictures already contain a cross, thus you don't have to paint anything.

You can paint (1,3)

, (3,1), (5,3) and (3,5) on the 6-th picture to get a cross in (3,3). That'll take you 4

minutes.

You can paint (1,2)

on the 7-th picture to get a cross in (4,2)

.

You can paint (2,2)

on the 8-th picture to get a cross in (2,2). You can, for example, paint (1,3), (3,1) and (3,3) to get a cross in (3,3) but that will take you 3 minutes instead of 1

.

There are 9 possible crosses you can get in minimum time on the 9

-th picture. One of them is in (1,1): paint (1,2) and (2,1).

题意:找补充次数最少的十字架

题解:暴力模拟,分别把每行每列的  *  个数存进数组,找出含有最长 * 的行列以及行列所在坐标i,j,还要判断a[i][j]是否为 .(特判),是的话次数还要减一

#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
vector<int>a[];
int xx[],yy[];
char s;
int main()
{
int t, n, m;
cin >> t;
while (t--)
{
int x = -, y = -, cnt = ,x_pos,y_pos;
cin >> n >> m;
for (int i = ; i < n; i++)
{
for (int j = ; j < m; j++)
{
cin >> s;
if (s == '.')
a[i].push_back();
else
a[i].push_back();
}
}
for (int i = ; i < n; i++)
{
cnt = ;
for (int j = ; j < m; j++)
{
cnt = cnt + a[i][j];
}
xx[i]=cnt;
if(cnt>x)
x=cnt;
}
for (int i = ; i < m; i++)
{
cnt = ;
for (int j = ; j < n; j++)
{
cnt = cnt + a[j][i];
}
yy[i]=cnt;
if(cnt>y)
y = cnt; }
int ans=,p=;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(xx[i]==x&&yy[j]==y&&a[i][j]==)
p=;
ans=min(m+n-xx[i]-yy[j],ans);
}
}
cout<<ans-p<<endl; for (int i = ; i < n; i++)//清空
a[i].clear();
}
// system("pause");
return ;
}

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

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

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

  2. Codeforces 1194B. Yet Another Crosses Problem

    传送门 直接枚举填满哪一行,然后看看这一行填满以后哪一列最小 这个预处理一下 $cnt[i]$ 表示初始时第 $i$ 列有几个位置填满就可以做到 $O(m)$ 对于所有情况取个 $min$ 就是答案, ...

  3. Educational Codeforces Round 68 Editorial

    题目链接:http://codeforces.com/contest/1194                                            A.Remove a Progre ...

  4. Educational Codeforces Round 68

    目录 Contest Info Solutions A.Remove a Progression B.Yet Another Crosses Problem C.From S To T D.1-2-K ...

  5. Educational Codeforces Round 68 (Rated for Div. 2)补题

    A. Remove a Progression 签到题,易知删去的为奇数,剩下的是正偶数数列. #include<iostream> using namespace std; int T; ...

  6. QFNU 10-02 19 training

    B - Yet Another Crosses Problem 题意:找如果使图中某一行某一列全部变成黑色,至少需要把多少个白方格变成黑方格 思路:直接找就可以,注意存储的时候要记得进行分开存储,存储 ...

  7. HDU 4978 A simple probability problem

    A simple probability problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  8. Problem O

    Problem Description Before bridges were common, ferries were used to transport cars across rivers. R ...

  9. 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 ...

随机推荐

  1. 「Luogu P2824 [HEOI2016/TJOI2016]排序」

    一道十分神奇的线段树题,做法十分的有趣. 前置芝士 线段树:一个十分基础的数据结构,在这道题中起了至关重要的作用. 一种基于01串的神奇的二分思想:在模拟赛中出现了这道题,可以先去做一下,这样可能有助 ...

  2. Java开发神器Lombok的使用与原理

    在面向对象编程中必不可少需要在代码中定义对象模型,而在基于Java的业务平台开发实践中尤其如此.相信大家在平时开发中也深有感触,本来是没有多少代码开发量的,但是因为定义的业务模型对象比较多,而需要重复 ...

  3. JavaScript图形实例:正弦曲线

    正弦曲线的坐标方程为: Y=A*SIN(X)    (A为振幅) 1.正弦曲线 在弧度为0~4π的正弦曲线上取360个点,将这些点用线连接起来,可以绘制出正弦曲线.编写如下的HTML代码. <! ...

  4. php中读取大文件实现方法详解

    php中读取大文件实现方法详解 来源:   时间:2013-09-05 19:27:01   阅读数:6186 分享到:0 [导读] 本文章来给各位同学介绍php中读取大文件实现方法详解吧,有需要了解 ...

  5. 首款中文渗透测试专用Linux系统—MagicBox

    1.     MagicBox的介绍 首款中文渗透测试专用Linux系统——MagicBox即将问世,中文名称:“魔方系统”,开发代号:Genesis.第一版本发布时间计划为2012年12月5日 这是 ...

  6. js 动画提示数据有变化

    let groupZiArray = $.....; for (let i = 1; i < groupZiArray.length; i++) { let $groupZi = $(group ...

  7. JAVA字符串与整形、浮点类型之间的相互转换总结

    1.字符串转化为整形.浮点类型 String s = "100"; //方法一 int a = Integer.parseInt(String s); Long.parseLong ...

  8. ch8 CSS 3列(等高文本列)

    css 3可以创建等高文本列,通过column-count.column-width.column-gap属性实现.假设标记如下: <h1>Socrates</h1> < ...

  9. Day4-A-最短路 HDU2544

    在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助 ...

  10. 记一次海洋cms任意代码执行漏洞拿shell(url一句话)

    实验环境:海洋CMS6.54(后续版本已该洞已补) 1.后台登录尝试 这个站点是个测试站,站里没什么数据. 进入admin.php,是带验证码的后台登录系统,没有验证码的可以用bp爆破.有验证码的也有 ...