codeforces B. Ohana Cleans Up
Ohana Matsumae is trying to clean a room, which is divided up into an n by n grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of rows that are completely clean. It is not allowed to sweep over the part of the column, Ohana can only sweep the whole column.
Return the maximum number of rows that she can make completely clean.
The first line of input will be a single integer n (1 ≤ n ≤ 100).
The next n lines will describe the state of the room. The i-th line will contain a binary string with n characters denoting the state of the i-th row of the room. The j-th character on this line is '1' if the j-th square in the i-th row is clean, and '0' if it is dirty.
The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.
4
0101
1000
1111
0101
2
3
111
111
111
3
In the first sample, Ohana can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean.
In the second sample, everything is already clean, so Ohana doesn't need to do anything.
/*
题意:选中某几列, 然后将这些列中为0的变为1, 为1的变为0,问最多能有多少行全为1 思路:假设最终答案包括第i行,那么如果a[i][j] 之前为0,则对应的这一列 j 一定是被选中的!
对于每一行,将这一行某一列为0的列作为选中的列,然后再遍历一遍数组,计算全1的行的个数。
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
char a[][], aa[][];
int main(){
int n;
scanf("%d", &n);
for(int i=; i<=n; ++i){
scanf("%s", a[i]+);
for(int j=; j<=n; ++j)
aa[i][j] = a[i][j];
}
int ans = ;
for(int k=; k<=n; ++k){
for(int i=; i<=n; ++i){
if(a[k][i]==''){
for(int j=; j<=n; ++j)
if(a[j][i]=='')
a[j][i]='';
else a[j][i] = '';
}
}
int ss = ;
for(int i=; i<=n; ++i)
for(int j=; j<=n; ++j)
if(a[i][j] == '')
break;
else if(j==n)
++ss;
if(ans < ss) ans = ss;
for(int i=; i<=n; ++i)
for(int j=; j<=n; ++j)
a[i][j] = aa[i][j];
}
printf("%d\n", ans);
return ;
}
codeforces B. Ohana Cleans Up的更多相关文章
- Codeforces Round #309 (Div. 2) B. Ohana Cleans Up 字符串水题
B. Ohana Cleans Up Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/554/pr ...
- B. Ohana Cleans Up(Codeforces Round #309 (Div. 2))
B. Ohana Cleans Up Ohana Matsumae is trying to clean a room, which is divided up into an n by n gr ...
- 贪心 Codeforces Round #309 (Div. 2) B. Ohana Cleans Up
题目传送门 /* 题意:某几列的数字翻转,使得某些行全为1,求出最多能有几行 想了好久都没有思路,看了代码才知道不用蠢办法,匹配初始相同的行最多能有几对就好了,不必翻转 */ #include < ...
- Codeforces554B:Ohana Cleans Up
B. Ohana Cleans Up Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d Ja ...
- Ohana Cleans Up
Ohana Cleans Up Description Ohana Matsumae is trying to clean a room, which is divided up into an n ...
- 【59.49%】【codeforces 554B】Ohana Cleans Up
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CodeForces 554B--Ohana Cleans Up
B. Ohana Cleans Up time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #309 (Div. 2)
A. Kyoya and Photobooks Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He ha ...
- CodeForces 554B(扫房间)
CodeForces 554B Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- 通读SDWebImage①--总体梳理、下载和缓存
本文目录 下载操作SDWebImageDownloaderOptions和下载过程实现 下载管理SDWebImageDownloader 缓存SDImageCache SDWebImageManage ...
- java基础3_循环语句,数组
java中的循环: Java中提供了3中循环结构: while do-while for ① 循环结构的作用? 可以不断重复执行循环结构中的代码: ② 上面的3个循环结构功能都是一样的,只是结构 ...
- TLV(类型—长度—值)格式及编码
转自: http://www.cnblogs.com/tml839720759/archive/2014/07/13/3841820.html 引子: 前段时间在项目中第一次接触TLV,项目中用这种格 ...
- toroiseSVN 无法连接服务器,提示unable connect to ……url 参数错误
之前使用的好好的,有天突然提示无法连接repository url,能ping通服务器,就是一直报错,找了很多方法,如: 1.删除缓存及缓存文件 2.删除软件并重新安装 3.关闭windows防火墙 ...
- 领域驱动有感<上>
最近看了<领域驱动设计:软件核心复杂性应对之道>,从字面上来看领域驱动就是解决软件复杂性问题的:然而领域驱动设计的门槛很高,没有很深厚的面向对象编码能力几乎不可能实践成功.Martin F ...
- Powershell 开启远程桌面
function Set-RemoteDesktop { while($InNumber -ne 6) { Write-Host " ###################### ...
- OS中atomic的实现解析
OS中atomic的实现解析 转自:http://my.oschina.net/majiage/blog/267409 摘要 atomic属性线程安全,会增加一定开销,但有些时候必须自定义ato ...
- IOS远程推送
IOS远程推送 一.关于推送通知 推送通知,也被叫做远程通知,是在iOS 3.0以后被引入的功能.是当程序没有启动或不在前台运行时,告诉用户有新消息的一种途径,是从外部服务器发送到应用程序上的.一般说 ...
- org.apache.jasper.JasperException:省略"/html/sysmaintain/authority/user/../../module/verify_login.jsp" not found
说明了JSP页面里引用安全登录页面的jsp路径代码:<%@ include file="../../module/verify_login.jsp"%>这句代码引用的路 ...
- 一道关于Promise应用的面试题
题目:红灯三秒亮一次,绿灯一秒亮一次,黄灯2秒亮一次:如何让三个灯不断交替重复亮灯?(用Promse实现) 三个亮灯函数已经存在: function red(){ console.log('red') ...