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 ...
随机推荐
- 使用maven搭建ssh框架
首先搭建sturts2框架,配置pom文件: <properties> <!-- 文件拷贝时的编码 --> <project.build.sourceEncoding&g ...
- Check a dll is x64 or x86
Just read two good articles on this topic: http://stackoverflow.com/questions/480696/how-to-find-if- ...
- HDU 1907 Nim博弈变形
1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...
- bootstrap之伪元素
bootstrap之伪元素 参考地址:http://www.cnblogs.com/keyi/p/5943178.html http://www.runoob.com/css/css-pseudo-e ...
- MongoDB aggregate 运用篇
基础知识 操作符介绍: $project:包含.排除.重命名和显示字段 $match:查询,需要同find()一样的参数 $limit:限制结果数量 $skip:忽略结果的数量 $sort:按照给定的 ...
- springMVC+spring+hibernate 框架整合实例
先说一下流程思路: 流程讲解1:首先访问会先定位到控制器.这就用到了过滤器配置文件"spring-mvc.xml".这个文件负责定义控制器的包路径.视图的格式等.其次从" ...
- 百度Ueditor配置问题
var URL = window.UEDITOR_HOME_URL || getUEBasePath(); 在ueditor.config.js中这一句是配置编辑器的网站根目录位置的,建议不要改,网上 ...
- svg格式的中国地图轮廓图
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C ...
- 【实战Java高并发程序设计 5】让普通变量也享受原子操作
[实战Java高并发程序设计 1]Java中的指针:Unsafe类 [实战Java高并发程序设计 2]无锁的对象引用:AtomicReference [实战Java高并发程序设计 3]带有时间戳的对象 ...
- The Swiss Army Knife of Data Structures … in C#
"I worked up a full implementation as well but I decided that it was too complicated to post in ...