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 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 test(s)

input

40101100011110101

output

2

input

3111111111

output

3

Note

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[105][105], aa[105][105];
int main(){
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; ++i){
        scanf("%s", a[i]+1);
        for(int j=1; j<=n; ++j)
            aa[i][j] = a[i][j];
    }
    int ans = 0;
    for(int k=1; k<=n; ++k){
        for(int i=1; i<=n; ++i){
            if(a[k][i]==‘0‘){
                for(int j=1; j<=n; ++j)
                    if(a[j][i]==‘0‘)
                        a[j][i]=‘1‘;
                    else a[j][i] = ‘0‘;
            }
        }
        int ss = 0;
        for(int i=1; i<=n; ++i)
            for(int j=1; j<=n; ++j)
                if(a[i][j] == ‘0‘)
                    break;
                else if(j==n)
                    ++ss;
        if(ans < ss)    ans = ss;
        for(int i=1; i<=n; ++i)
            for(int j=1; j<=n; ++j)
                a[i][j] = aa[i][j];
    }
    printf("%d\n", ans);
    return 0;
}
时间: 2024-10-24 18:13:36

codeforces B. Ohana Cleans Up的相关文章

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

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

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: i

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

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

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

#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

CodeForces 554B()

  CodeForces 554B Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u 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.