https://codeforc.es/contest/1194/problem/B

好像也没什么思维,就是一个水题,不过蛮有趣的。意思是找缺黑色最少的行列十字。用O(n)的空间预处理掉一维,然后用O(n)的时间根据另一维计算出答案。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; int n, m;
string g[50005];
int rq[50005]; int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
//freopen("Yinku.out", "w", stdout);
#endif // Yinku
int q;
while(~scanf("%d", &q)) {
while(q--) {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) {
cin >> g[i];
g[i] = '$' + g[i];
}
int minans = n * m;
for(int i = 1; i <= n; i++) {
rq[i] = 0;
for(int j = 1; j <= m; j++) {
if(g[i][j] == '.') {
rq[i]++;
}
}
}
for(int j = 1; j <= m; j++) {
int cq = 0;
for(int i = 1; i <= n; i++) {
if(g[i][j] == '.') {
cq++;
}
}
for(int i = 1; i <= n; i++) {
minans = min(minans, rq[i] + cq - (g[i][j] == '.'));
}
}
printf("%d\n",minans);
}
}
}

Codeforces - 1194B - Yet Another Crosses Problem - 水题的更多相关文章

  1. Codeforces 1194B. Yet Another Crosses Problem

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

  2. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  3. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

  4. Codeforces Testing Round #12 A. Divisibility 水题

    A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  5. Codeforces Beta Round #37 A. Towers 水题

    A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...

  6. hdu-5867 Water problem(水题)

    题目链接: Water problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  7. codeforces 677A A. Vanya and Fence(水题)

    题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...

  8. CodeForces 690C1 Brain Network (easy) (水题,判断树)

    题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...

  9. poj 1658 Eva's Problem(水题)

    一.Description Eva的家庭作业里有很多数列填空练习.填空练习的要求是:已知数列的前四项,填出第五项.因为已经知道这些数列只可能是等差或等比数列,她决定写一个程序来完成这些练习. Inpu ...

随机推荐

  1. 解决nginx proxy_pass反向代理cookie,session丢失的问题

    参考地址:https://www.jianshu.com/p/34abe7eb6f0b 为什么cookie 会丢失? 比如说一个没有经过代理的地址 : http://127.0.0.1/project ...

  2. mac上如何搜索文件?

    在Mac上如果你用会了搜索功能那绝对是个事半功倍的技巧.因为Mac本身有强大的文件索引能力, 可以帮你快速的找到你需要的文件.就好比我要找到上周修改过的word文档应该怎么办? * 使用语音命令让Si ...

  3. 微信公众号开发(二)获取access_token

    参考:https://www.cnblogs.com/liuhongfeng/p/4848851.html 一:介绍. 接口调用请求说明 http请求方式: GET https://api.weixi ...

  4. 前端通过axios和FormData实现文件上传功能遇到的坑

    使用element-ui中的upload上传组件,前端上传数据参数已经传过去了,但是后端 (java) 接不到数据 (null) [解决方案] html部分: <el-button type=& ...

  5. pycharm默认的模板修改python script

    #!/usr/bin/env python # encoding: utf-8 #set( $SITE = "https://www.cnblogs.com/c-x-a" ) &q ...

  6. php面试专题---17、MySQL的SQL语句编写考点

    php面试专题---17.MySQL的SQL语句编写考点 一.总结 一句话总结: 注意:只写精品 1.MySQL的关联UPDATE语句? 关键UPDATE A,B:UPDATE A,B SET A.c ...

  7. 清北学堂Day 6之STL

    电脑突然一炸,什么都没有保存,凉了.(又出现了笔记凉凉事件嘤嘤嘤) 行吧慢慢回忆 就算我们会手写,我们也要学STL.吸了O2的STL可是要上天的. 数据结构 pair 使用方式: pair<类型 ...

  8. nas请求响应示意图

    curl nginx(proxy_connect) nginx(NAS) | | | | | | (1) |-- CONNECT 443 -> | | | | | | |---- [ TCP c ...

  9. E:\Postgresql\pgAdmin4_binaryPath

    e Path to the directory containing the EDB Advanced Server utility programs (pg_dump, pg_restore etc ...

  10. linux文件夹 权限为所有用户可 读写

    使用命令: sudo chmod dirname -R