博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【59.49%】【codeforces 554B】Ohana Cleans Up
阅读量:5037 次
发布时间:2019-06-12

本文共 2983 字,大约阅读时间需要 9 分钟。

time limit per test2 seconds

memory limit per test256 megabytes
inputstandard input
outputstandard output
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.

Examples

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.

【题目链接】:

【题解】

因为最后肯定有一行是全为1的(全都是干净的);
那么就枚举最后哪一行全是干净的.
然后看看要让这一行全部是干净的需要把哪些列全部取反.
这样就能知道整个图有多少行是全为1的了;
取最大值就好.
【完整代码】

#include 
using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define LL long long#define rep1(i,a,b) for (int i = a;i <= b;i++)#define rep2(i,a,b) for (int i = a;i >= b;i--)#define mp make_pair#define pb push_back#define fi first#define se second#define rei(x) scanf("%d",&x)#define rel(x) scanf("%I64d",&x)#define pri(x) printf("%d",x)#define prl(x) printf("%I64d",x)typedef pair
pii;typedef pair
pll;const int MAXN = 100+10;const int dx[9] = {
0,1,-1,0,0,-1,-1,1,1};const int dy[9] = {
0,0,0,-1,1,-1,1,-1,1};const double pi = acos(-1.0);int n;int a[MAXN][MAXN];char s[MAXN];bool bo[MAXN];int main(){ //freopen("F:\\rush.txt","r",stdin); rei(n); rep1(i,1,n) { scanf("%s",s+1); rep1(j,1,n) a[i][j] = s[j]-'0'; } int ans = 0; rep1(i,1,n) { memset(bo,false,sizeof(bo)); rep1(j,1,n) if (a[i][j]==0) bo[j] = true; int cnt = 0; rep1(j,1,n) { bool ok = true; rep1(k,1,n) if ((a[j][k]==0 && !bo[k])||(a[j][k]==1 && bo[k])) { ok = false; break; } if (ok) cnt++; } ans = max(ans,cnt); } cout << ans << endl; return 0;}

转载于:https://www.cnblogs.com/AWCXV/p/7626834.html

你可能感兴趣的文章
HTML&CSS基础学习笔记1.28-给网页添加一个css样式
查看>>
windows上面链接使用linux上面的docker daemon
查看>>
Redis事务
查看>>
Web框架和Django基础
查看>>
python中的逻辑操作符
查看>>
CSS兼容性常见问题总结
查看>>
HDU 1548 A strange lift (Dijkstra)
查看>>
每天一个小程序—0005题(批量处理图片大小)
查看>>
C# 启动进程和杀死进程
查看>>
tcp实现交互
查看>>
IIS的各种身份验证详细测试
查看>>
JavaScript特效源码(3、菜单特效)
查看>>
聊聊、Zookeeper Linux 单服务
查看>>
Linux常用命令总结
查看>>
KRPano动态热点专用素材图50多个,加动态热点使用方法
查看>>
yii模型ar中备忘
查看>>
C#线程入门
查看>>
CSS清除浮动方法
查看>>
JVM内存回收机制简述
查看>>
洛咕 P2480 [SDOI2010]古代猪文
查看>>