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 ...
随机推荐
- Android -- 软键盘
1. 应用启动后,自动打开软键盘 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD ...
- 文件处理命令:awk
awk擅长于对数据进行分析并生成报告,简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再进行各种分析处理. 使用方法:awk '{pattern +action}' {fi ...
- js基础3
内置对象 内置对象就是JS提供的一套工具箱,我们通过内置可以很方便的进行一些操作. Math对象: Math.ceil() //向上取整,天花板 Math.floor() //向下取整,地板 Math ...
- Python3.5 Day2作业:购物车程序
需求: 1. 启动程序后,用户通过账号密码登录,然后打印商品列表. 2. 允许用户根据商品编号购买商品. 3. 用户选择商品后,检测余额是否足够,够就直接扣款,不够就提醒充值. 4. 可随时退出,退出 ...
- Linux Shell 脚本调试
方法如下所示:(1) 使用选项–x,启用shell脚本的跟踪调试功能: $ bash -x script.sh 运行带有-x标志的脚本可以打印出所执行的每一行命令以及当前状态.注意,你也可以使用sh ...
- *HDU 1757 矩阵乘法
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- C++ 回调函数的定义与用法
一回调函数 我们经常在C++设计时通过使用回调函数可以使有些应用(如定时器事件回调处理.用回调函数记录某操作进度等)变得非常方便和符合逻辑,那么它的内在机制如何呢,怎么定义呢?它和其它函数(比如钩子函 ...
- The Solution of UESTC 2016 Summer Training #1 Div.2 Problem A
Link http://acm.hust.edu.cn/vjudge/contest/121539#problem/A Description standard input/output Haneen ...
- ios使用CocoaHTTPServer实现文件共享
CocoaHTTPServer下载地址:https://github.com/robbiehanson/CocoaHTTPServer 实现效果:在电脑端输入192.168.0.100:8080,出现 ...
- Unity 5.3.5p8 C#编译器升级
Unity 5.3.5p8的C#编译器升级 注意:该版本是单独升级C#编译器的测试版!请使用文中提供的下载链接! 基于Unity 5.3.5p8的C#编译器升级!下载链接 试用该版本前请先备份项目,遇 ...