Codeforces554B:Ohana Cleans Up
B. Ohana Cleans Up
64-bit integer IO format: %I64d Java class name: (Any)
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
4
0101
1000
1111
0101
2
3
111
111
111
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表示干净,有一个神奇厉害的大妈,每次扫地只扫一列,扫完之后,干净变成不干净,不干净变成干净(如此神奇),问最多能使得几行变得干净。
思路:遍历一遍即可,看看最多有几行是相同的。用vi[i]保存遍历过的,防止重复搜索。
代码:
#include <stdio.h>
#include <iostream>
#include <string.h> using namespace std; int main(){
char s[][];
int vi[]={};
int max=;
int num=;
int n;
cin>>n;
for(int i=;i<n;i++)
cin>>s[i];
for(int i=;i<n;i++){
num=;
if(vi[i]==)
continue;
vi[i]=;
for(int j=;j<n ;j++){
if(strcmp(s[i],s[j])==){num++;vi[j]=;}
}
if(max<num)
max=num;
}
cout<<max;
}
Codeforces554B:Ohana Cleans Up的更多相关文章
- codeforces B. Ohana Cleans Up
B. Ohana Cleans Up Ohana Matsumae is trying to clean a room, which is divided up into an n by n grid ...
- Ohana Cleans Up
Ohana Cleans Up Description Ohana Matsumae is trying to clean a room, which is divided up into an n ...
- Codeforces Round #309 (Div. 2) B. Ohana Cleans Up 字符串水题
B. Ohana Cleans Up Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/554/pr ...
- B. Ohana Cleans Up(Codeforces Round #309 (Div. 2))
B. Ohana Cleans Up Ohana Matsumae is trying to clean a room, which is divided up into an n by n gr ...
- 贪心 Codeforces Round #309 (Div. 2) B. Ohana Cleans Up
题目传送门 /* 题意:某几列的数字翻转,使得某些行全为1,求出最多能有几行 想了好久都没有思路,看了代码才知道不用蠢办法,匹配初始相同的行最多能有几对就好了,不必翻转 */ #include < ...
- 【59.49%】【codeforces 554B】Ohana Cleans Up
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CodeForces 554B--Ohana Cleans Up
B. Ohana Cleans Up time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #309 (Div. 2)
A. Kyoya and Photobooks Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He ha ...
- Java资源大全中文版(Awesome最新版)
Awesome系列的Java资源整理.awesome-java 就是akullpp发起维护的Java资源列表,内容包括:构建工具.数据库.框架.模板.安全.代码分析.日志.第三方库.书籍.Java 站 ...
随机推荐
- python之路九
paramiko paramiko模块是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接 ssh执行命令: import paramikossh = pa ...
- Spring预处理
当需要在某些Spring项目一启动,就执行某些操作时,需要实现改接口ApplicationListener,重写onApplicationEvent方法,将需要的预处理操作全部写在该方法中 当初始化完 ...
- Android 手机摇一摇功能的实现
package myapplication.com.myapp.activity; public class Home_Activity extends AppCompatActivity{ //传感 ...
- 在asp.net mvc模式中使用PartialView返回部分HTML
PartialView(返回HTML(局部)) 在asp.net mvc中返回View时使用的是ViewResult,它继承自ViewResultBase 同时它还有个兄弟PartialViewRes ...
- Sass安装(windows版)
Sass安装(windows版) 在 Windows 平台下安装 Ruby 需要先有 Ruby 安装包,大家可以到 Ruby 的官网(http://rubyinstaller.org/download ...
- iOS中滤镜处理及相关内存泄漏问题的解决
最近工作之余在做一个美图秀秀的仿品 做到滤镜这块的时候 自己就参考了网上几位博主(名字忘了记,非常抱歉)的博客,但是发现跟着他们的demo做的滤镜处理,都会有很严重的内存泄漏,于是就自己按照大体的思 ...
- VR系统的组成
转载请声明转载地址:http://www.cnblogs.com/Rodolfo/,违者必究. 一个典型的虚拟现实系统主要由计算机.输入/输出设备.应用软件和数据库等部分组成. 1.计算机 在虚拟现实 ...
- C语言中do...while(0)的妙用(转载)
转载来自:C语言中do...while(0)的妙用,感谢分享. 在linux内核代码中,经常看到do...while(0)的宏,do...while(0)有很多作用,下面举出几个: 1.避免goto语 ...
- InnoDB VS MyISAM
首先都是MySql存储引擎.数据库的考虑点一般就是事务(ACID),然后牵扯出的锁机制.如果你需要事务,那就只能选InnoDB了.如果你还需要外键约束,你也只能选择InnoDB.这个是两者最大的区别. ...
- vim 标签命令
设置标签:ma 跳转到标签:`a 查看当前所有标签:marks 删除标签:delmarks a 删除所有标签:delmarks! 不包括[A-Z]和[0-9]标签.