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. openstack stein部署手册 7. nova-compute

    # 安装程序包 yum install -y openstack-nova-compute # 变更配置文件 cd /etc/nova mv nova.conf nova.conf.org cat & ...

  2. 如何查看Codeforces的GYM中比赛的数据

    前置条件:黄名(rating >= 2100) 或者 紫名(rating >= 1900)并且打过30场计分的比赛. 开启:首先打开GYM的界面,如果符合要求会在右边展示出一个Coach ...

  3. centos7 内网可达,外网不可达

    参考:https://www.cnblogs.com/operationhome/p/10207257.html 网关地址改为192.168.1.1

  4. cmd获取管理员权限等

    鼠标点点点的略过 可输入命令 runas /user:Administrator cmd 或 runas /noprofile /user:Administrator cmd Administrato ...

  5. word从任意页设置页码

    把所有页都设置页码 首先设置分隔符,下一页 在第二节中,找到插入页码,设置起始页码为1即可

  6. Python操作cx_Oracle笔记

    参考文章: http://cx-oracle.readthedocs.io/en/latest/cursor.html # 创建数据库连接 ordb = Oracle.connect("{0 ...

  7. 使用Fabric在tomcat中部署应用的问题总结

    关闭tomcat时 A.为什么调用shutdown时,报错连接拒绝 结论——很可能是因为tomcat没启动或没完全启动:而这个时候调用shutdown就会出现此类报错 解决方法:time.sleep ...

  8. linux运维、架构之路-HTTP服务

    一.HTTP协议 1.介绍 HTTP协议,全称HyperText Transfer Protocol,中文名为超文本传输协议,是互联网中最常用的一种网络协议.HTTP协议是互联网上常用的通信协议之一. ...

  9. maven构建docker镜像异常

    由于没有配置ip+2375端口,导致每次跑的时候,都是连接本地的,一直会报错 [ERROR] Failed to execute goal com.spotify:docker-maven-plugi ...

  10. 循序渐进实现仿QQ界面(一):园角矩形与双缓冲贴图窗口

    印象里仿QQ界面的程序应该有很多,搜了一下,虽然出来一大堆,排除了重复的,却只有两三个,没我想象的好.经常看到CSDN上有人问,QQ这个功能怎么实现,那个界面怎么实现,归纳了一下,决定写这么一个仿QQ ...