CodeForces 554B Ohana Cleans Up 【思维+map】

Ohana Cleans Up

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. 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 Input
Input
4
0101
1000
1111
0101
Output
2
Input
3
111
111
111
Output
3
Hint
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.


题意:给你n*n的图,每格只有0,1,0代表未打扫,1代表打扫,每次只能打扫一列效果是0变成1,1变成0,问你每行都为1的最大行数是多少;

思路:先看第一列,可以打扫也可以不打扫,0,1是对立的,表示如果选择0的行数,那么1的行数是不能要的,第2列的选择也是如此,要么选0的行要么选1的行,知道最后一列,我们最后选择的其实就是一个相同的序列,如果任何一个数不相同,那么这两个就不可能在一组之中,,我们只要找所有相同行最大次数就行了;

失误:思路想出来了,想着用MAP做会很简单,没想到map的遍历啥都忘了,最后还好想到了方法;

代码如下:

#include
#include
#include
#include
using namespace std;

map MP;

int main()
{
	int N,i;
	char str[1000];
	while(~scanf("%d",&N))
	{   
	    MP.clear();int ans=0;
		for(i=1;i<=N;++i)
		{
			 scanf("%s",str);
		     ans=max(++MP[str],ans);//每加一次都比较一下保持最大 
		} 
		printf("%d\n",ans);
	}
	return 0;
}


你可能感兴趣的:(小数学,STL,暑假集训)