博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
B. Yet Another Crosses Problem
阅读量:4313 次
发布时间:2019-06-06

本文共 3503 字,大约阅读时间需要 11 分钟。

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 1xn and 1ym, 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

(1q5104

) — the number of queries.

The first line of each query contains two integers n

and m (1n,m5104, nm4105

) — 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 n5104

and nm4105

.

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
95 5..*....*..*****..*....*..3 4****.*...*..4 3****..*..*..5 5******.*.******..*.*..***1 4****5 5.......*...***...*.......5 3....*..*.***.*.3 3.*.*.*.*.4 4*.**....*.***.**
Output
Copy
000004112
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
#include
#include
#include
#include
using namespace std;vector
a[500004];int xx[500005],yy[500005];char s;int main(){ int t, n, m; cin >> t; while (t--) { int x = -1, y = -1, cnt = 0,x_pos,y_pos; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> s; if (s == '.') a[i].push_back(0); else a[i].push_back(1); } } for (int i = 0; i < n; i++) { cnt = 0; for (int j = 0; j < m; j++) { cnt = cnt + a[i][j]; } xx[i]=cnt; if(cnt>x) x=cnt; } for (int i = 0; i < m; i++) { cnt = 0; for (int j = 0; j < n; j++) { cnt = cnt + a[j][i]; } yy[i]=cnt; if(cnt>y) y = cnt; } int ans=999999,p=0; for(int i=0;i

 

转载于:https://www.cnblogs.com/-citywall123/p/11189360.html

你可能感兴趣的文章
Mybatis generator生成工具简单介绍
查看>>
Shellshock漏洞复现
查看>>
邮箱爆破
查看>>
Parrot os安装docker及docker-compose
查看>>
Parrot os配置源更新
查看>>
HTTP/2 简介及https原理
查看>>
JS代码静态分析及挖掘
查看>>
Jenkins漏洞利用复现
查看>>
WM_PAINT
查看>>
动态查看服务器打印日志
查看>>
来自官方的 windows 7 快捷键大全
查看>>
Deep RL Bootcamp Lecture 8 Derivative Free Methods
查看>>
iOS 关于Xcode上的Other linker flags
查看>>
.NET中的程序集(Assembly)
查看>>
第17章:MongoDB-聚合操作--聚合管道--$group
查看>>
Oracle 中wmsys.wm_concat拼接字符串,结果过长报错解决
查看>>
angularjs基础——控制器
查看>>
前端设计师如何提高UI界面中的阅读性
查看>>
APP版本号记录
查看>>
母函数
查看>>