B. Ohana Cleans Up

题目链接:http://codeforces.com/problemset/problem/554/B

题目大意:

奥哈马清理一间被分成n*n格的房间,每格使用数字‘1’和‘0’来表示状态,单格用1表示,则表明是干净的,用0表示则是脏的。清理时,奥哈马只能一整列的打扫,而且被打扫的单格如果是干净(1)的就会变脏(0),而如果是脏(0)的就会变干净(1)。清理的列数不定,问他清理后最多有多少行能完全干净?

案例:

Input

        4        0101        1000        1111        0101

Output

        2

Input

        3        111        111        111

Output

        3

题目分析:

不计列数清理多少次,则可忽略此处条件,从行数考虑。行与行相同则清理后结果相同,所以本题可以从行之间相同的初始状态着手,计算出最大的行相同数即为所求。

源代码:

 1 #include<iostream>
 2 #include<string>
 3 using namespace std;
 4 #define max 100
 5 int main()
 6 {
 7     int n,p,x=0,i;
 8     string s[max];
 9     cin>>n;//输入行(列)数
10     for(i=0;i<n;i++)
11        cin>>s[i];//输入每行的初始状况
12     for(i=0;i<n;i++)
13     {  for(int j=0;j<n;j++)
14           if(s[i]==s[j])
15              p++;//找出具有相同状态的行数
16        if(p>x) x=p;//将最大的行数赋值给x
17        p=0;
18     }
19     cout<<x<<endl;
20     return 0;
21 }
时间: 2024-10-12 12:16:49

B. Ohana Cleans Up的相关文章

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 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 swe

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 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 swe

Ohana Cleans Up

Ohana Cleans Up 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: i

贪心 Codeforces Round #309 (Div. 2) B. Ohana Cleans Up

题目传送门 1 /* 2 题意:某几列的数字翻转,使得某些行全为1,求出最多能有几行 3 想了好久都没有思路,看了代码才知道不用蠢办法,匹配初始相同的行最多能有几对就好了,不必翻转 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <string> 8 #include <cmath> 9 #include <iostream> 10 using namespace std; 1

Codeforces554B:Ohana Cleans Up

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 sq

Codeforces 554B. Ohana Cleans Up

output standard 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

Ohana Cleans Up0101

题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=187195 题意: 一组数据只有0和1,0表示地板是脏的,1表示地板是干净的,现在,拖地板只能一列一列的拖,被拖的0会变为1,1会变为0,需找出最多可以有多少行地板是完全干净的. (可以不拖地板) 案例: 1)input 4 0101 1000 1111            0101           output 2 2) input 3 1 1 1 1

#309 (div.2) B. Ohana Cleans Up

1.题目描述:点击打开链接 2.解题思路:本题是一道简单的找最大值问题.只需要找出完全相同的行中个数那一行即可,输出它的个数.由于给定的范围比较小,可以直接用O(N^3)的算法解决.查找的时候用一个mark数组来标记哪些行已经查找过了,这样可以避免重复查找. 3.代码: #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<string> #include<s

Spark Standalone模式

Spark Standalone模式 安装Spark Standalone集群 手动启动集群 集群创建脚本 提交应用到集群 创建Spark应用 资源调度及分配 监控与日志 与Hadoop共存 配置网络安全端口 高可用性 基于Zookeeper的Master 本地系统的单节点恢复 除了运行在mesos或yarn集群管理器中,spark也提供了简单的standalone部署模式.你可以通过手动启动master和worker节点来创建集群,或者用官网提供的启动脚本.这些守护进程也可以只在一台机器上以便