Codeforces - 1194B - Yet Another Crosses Problem - 水题
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 - 水题的更多相关文章
- Codeforces 1194B. Yet Another Crosses Problem
传送门 直接枚举填满哪一行,然后看看这一行填满以后哪一列最小 这个预处理一下 $cnt[i]$ 表示初始时第 $i$ 列有几个位置填满就可以做到 $O(m)$ 对于所有情况取个 $min$ 就是答案, ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Beta Round #37 A. Towers 水题
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...
- hdu-5867 Water problem(水题)
题目链接: Water problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- codeforces 677A A. Vanya and Fence(水题)
题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...
- CodeForces 690C1 Brain Network (easy) (水题,判断树)
题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...
- poj 1658 Eva's Problem(水题)
一.Description Eva的家庭作业里有很多数列填空练习.填空练习的要求是:已知数列的前四项,填出第五项.因为已经知道这些数列只可能是等差或等比数列,她决定写一个程序来完成这些练习. Inpu ...
随机推荐
- 如何同步发送put或者delete请求
1.必须把前端发送方式改为post . 2.在web.xml中配置一个filter:HiddenHttpMethodFilter过滤器 3.必须携带一个键值对,key=_method, value= ...
- 机器学习-K-means聚类及算法实现(基于R语言)
K-means聚类 将n个观测点,按一定标准(数据点的相似度),划归到k个聚类(用户划分.产品类别划分等)中. 重要概念:质心 K-means聚类要求的变量是数值变量,方便计算距离. 算法实现 R语言 ...
- Windows 10 系统获取密钥方法
方法一: 快捷键 win+R 打开运行窗口,输入 regedit 打开注册表编辑器,选择 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\Curren ...
- ghci对haskell的类型推导
今天这篇文章分析一下ghci交互解释器对类型的推导. 假设有函数fn定义如下: let fn = map map 现在fn的类型是: map map :: [a -> b] -> [[a] ...
- 获取服务进程server.exe的pid(0号崩溃)
#include "stdafx.h" #include <windows.h> #include <iostream> #include <COMD ...
- POJ 2018 Best Cow Fences (二分答案构造新权值 or 斜率优化)
$ POJ~2018~Best~Cow~ Fences $(二分答案构造新权值) $ solution: $ 题目大意: 给定正整数数列 $ A $ ,求一个平均数最大的长度不小于 $ L $ 的子段 ...
- Ajax工作原理及C/S与B/S的区别
工作原理 Ajax 基本上就是把 JavaScript 技术和 XMLHttpRequest 对象放在 Web 表单和服务器之间.当用户填写表单时,数据发送给一些 JavaScript 代码而不是直接 ...
- gitignore 忽略文件
*.project*.prefs*.classpath*.gitignore#ignore thumbnails created by windowsThumbs.db#Ignore files bu ...
- Flask 之装饰器有关
- 先记住一句话:自定义python装饰器时一定要记住使用@functools.wraps(func)修饰wrapper - 在Flask中使用装饰器遇到AssertionError: View fu ...
- struts2+ajax 前后端传值
摘要: 主要实现步骤如下: 1.JSP页面使用脚本代码执行ajax请求 2.Action中查询出需要返回的数据,并转换为json类型模式数据 3.配置struts.xml文件 4.页面脚本接受并处理数 ...