Ohana Cleans Up

Ohana Cleans Up

Description

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.

Input

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.

Output

The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.

Sample Input1

Input

40101100011110101

Output

2

Sample Input2

Input

3111111111

Output

3

题意:

给定一个由n*n块地砖铺成的房间,每块砖用0表示未打扫,1表示已打扫。

要求打扫时只能整列地扫,未打扫的会变为已打扫,已打扫的会变为未打扫。

即1会变成0,而0会变成1,

求一种打扫方案,使得打扫完后整行地砖均为已打扫的行数最大。

分析:

如果两行地砖状态完全相同,那么无论如何打扫,这两行地砖的状态始终都是完全相同的(因为打扫的时候必须打扫整列)。

要使最后整行为1的行数最大,就是求开始时整行地砖处于相同状态的行数最大。

所以只需将整行看做一个字符串,将出现最多的字符串的次数输出。

 1 #include<iostream>
 2 #include<string>
 3 using namespace std;
 4 #define maxn 100
 5 int n,count=0;
 6 string a[maxn];
 7 int main()
 8 {int x=0;
 9     cin>>n;
10 for(int i=0;i<n;i++)
11   cin>>a[i];
12 for(int  l=0;l<n;l++)
13 {  count=0;
14  for( int k=l;k<n;k++)
15   if(a[l]==a[k])
16     count++;
17 if(count>x)
18 x=count;
19 }
20 cout<<x<<endl;
21 return 0;
22 }

 

				
时间: 2024-10-14 20:38:27

Ohana Cleans Up的相关文章

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 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 swe

codeforces B. Ohana Cleans Up

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 swe

贪心 Codeforces Round #309 (Div. 2) B. Ohana Cleans Up

题目传送门 1 /* 2 题意:某几列的数字翻转,使得某些行全为1,求出最多能有几行 3 想了好久都没有思路,看了代码才知道不用蠢办法,匹配初始相同的行最多能有几对就好了,不必翻转 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <string> 8 #include <cmath> 9 #include <iostream> 10 using namespace std; 1

Codeforces554B: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 sq

Codeforces 554B. Ohana Cleans Up

output standard output 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

Ohana Cleans Up0101

题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=187195 题意: 一组数据只有0和1,0表示地板是脏的,1表示地板是干净的,现在,拖地板只能一列一列的拖,被拖的0会变为1,1会变为0,需找出最多可以有多少行地板是完全干净的. (可以不拖地板) 案例: 1)input 4 0101 1000 1111            0101           output 2 2) input 3 1 1 1 1

B. Ohana Cleans Up

题目链接:http://codeforces.com/problemset/problem/554/B 题目大意: 奥哈马清理一间被分成n*n格的房间,每格使用数字‘1’和‘0’来表示状态,单格用1表示,则表明是干净的,用0表示则是脏的.清理时,奥哈马只能一整列的打扫,而且被打扫的单格如果是干净(1)的就会变脏(0),而如果是脏(0)的就会变干净(1).清理的列数不定,问他清理后最多有多少行能完全干净? 案例: Input 4 0101 1000 1111 0101 Output 2 Input

#309 (div.2) B. Ohana Cleans Up

1.题目描述:点击打开链接 2.解题思路:本题是一道简单的找最大值问题.只需要找出完全相同的行中个数那一行即可,输出它的个数.由于给定的范围比较小,可以直接用O(N^3)的算法解决.查找的时候用一个mark数组来标记哪些行已经查找过了,这样可以避免重复查找. 3.代码: #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<string> #include<s

Spark Standalone模式

Spark Standalone模式 安装Spark Standalone集群 手动启动集群 集群创建脚本 提交应用到集群 创建Spark应用 资源调度及分配 监控与日志 与Hadoop共存 配置网络安全端口 高可用性 基于Zookeeper的Master 本地系统的单节点恢复 除了运行在mesos或yarn集群管理器中,spark也提供了简单的standalone部署模式.你可以通过手动启动master和worker节点来创建集群,或者用官网提供的启动脚本.这些守护进程也可以只在一台机器上以便