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

24 篇文章 0 订阅
16 篇文章 0 订阅

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<cstdio>
#include<map>
#include<string>
#include<algorithm>
using namespace std;

map<string,int> 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值