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

原题:http://codeforces.com/contest/554/problem/B


题目大意: 给个n x n的binary矩阵, 只能翻转(0->1,1->0), 问如何翻转, 让全是1的总数最大.


分析: 因为每次翻转列的时候, 每个行都要翻转, 所以只要找到最大数目的相同的行. 就可以了.

public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.readInt();
        HashMap<String, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String s = in.readString();
            if (!map.containsKey(s))
                map.put(s,0);
            map.put(s,map.get(s)+1);
        }
        int max = 0 ;
        Iterator<Integer> integerIterator = map.values().iterator();
        while (integerIterator.hasNext())
            max=Math.max(max,integerIterator.next());
        out.print(max);
    }