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
4
0101
1000
1111
0101
output
2
input
3
111
111
111
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;
}









本文转自 小眼儿 博客园博客,原文链接:http://www.cnblogs.com/hujunzheng/p/4601289.html,如需转载请自行联系原作者
目录
相关文章
codeforces 312
A. Whose sentence is it?
47 0
codeforces 322 B Ciel and Flowers
有红绿蓝三种颜色的画,每种拿三朵可以组成一束花,或者各拿一朵组成花束,告诉你每种花的数目,求出可能组成最多的花束。 如果你的代码过不了,考虑一下 8 8 9这种组合。 因为数据量很大,我的思想就是局部和总体采用不同的策略。
47 0
|
C++
codeforces 305 C. Ivan and Powers of Two
我的思路是这样的,由2^a+2^a = 2^(a+1)可知,如果有两个连续的数a,我们可以把他们合并为a+1放入集合中,使集合中没有重复的数,我可以用stl里的set。如果想要满足题目中的要求,集合中必须有最大那个数个元素,缺多少就可以计算出来了。
29 0
codeforces 322 A Ciel and Dancing
有n个男孩和m个女孩,他们要结对跳舞,每对要有一个女孩和一个男孩,而且其中一个要求之前没有和其他人结对,求出最大可以结多少对。
35 0
codeforces 327 A Ciel and Dancing
给你一串只有0和1的数字,然后对某一区间的数翻转1次(0变1 1变0),只翻转一次而且不能不翻转,然后让你计算最多可能出现多少个1。 这里要注意很多细节 比如全为1,要求必须翻转,这时候我们只要翻转一个1就可以了,对于其他情况,我们只要计算区间里面如果0多于1,将其翻转后计算1的总数,然后取最大值。
40 0
|
人工智能
Codeforces 777C Alyona and Spreadsheet
C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard ...
1156 0
Codeforces 591B Rebranding
B. Rebranding time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output ...
852 0
|
人工智能
Codeforces 719B Anatoly and Cockroaches
B. Anatoly and Cockroaches time limit per test:1 second memory limit per test:256 megabytes input:standard input output:stan...
890 0