CodeForces 554B (scan the room), codeforces554b
CodeForces 554B
Time Limit:2000 MS
Memory Limit:262144KB
64bit IO Format:% I64d & % I64u
Description
Ohana Matsumae is trying to clean a room, which is divided up intoNByNGrid 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 integerN(1 digit ≤ DigitNLimit ≤ limit 100 ).
The nextNLines will describe the state of the room.I-Th line will contain a binary stringNCharacters denoting the state ofI-Th row of the room.J-Th character on this line is '1' ifJ-Th square inI-Th row is clean, and '0' if it is dirty.
Output
The output shoshould be a single line containing an integer equal to a maximum possible number of rows that are completely clean.
Sample Input
Input
4
0101
1000
1111
0101
Output
2
Input
3
111
111
111
Output
3
Question: given a room made up of n * n floor tiles, each brick is 0 indicating that it has not been cleaned, and 1 indicates that it has been cleaned. Only one full column of floor tiles can be scanned at a time. If the floor tiles are not cleaned, they are cleaned and not cleaned. That is, 1 will change to 0, and 0 will change to 1. Find a cleaning solution, so that the whole line of floor tile after cleaning is the maximum number of rows that have been cleaned.
It seems like there is no solution, but actually there is a solution. It is actually very simple ..
First, we can see that if the two rows of floor tiles are in the same State, the two rows of floor tiles are always in the same State regardless of how they are cleaned (because the whole column must be cleaned ). If the floor tiles of some rows are in full state 1 after cleaning, the corresponding columns of these rows are in the same State. Now that we want to maximize the number of rows in the final Integer Behavior 1, we actually need to find the maximum number of rows in the same state at the beginning. Think of the entire line as a string and use map directly. The string that records the most frequent occurrences.
# Include <stdio. h> # include <string. h ># include <algorithm> using namespace std; char a [102] [102]; int max (int x, int y) {if (x <y) return y; else return x;} int main () {int n, I, j, k = 0; scanf ("% d", & n); for (I = 1; I <= n; I ++) {scanf ("% s", a [I]) ;}for (I = 1; I <= n; I ++) {int s = 0; for (j = 1; j <= n; j ++) {if (strcmp (a [I], a [j]) = 0) // compare two arrays s ++;} k = max (k, s);} printf ("% d \ n", k); return 0 ;}