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

1 1 1

output

3

思路分析:

分析题可知,只要找出相同的行数中最多可以有几行,那就是需要输出的数,数组最好为string型,这样在每行数进行比较时就可以直接比较。

在比较时,找出所有相同的字符串的个数p,利用打擂台的方法把最大的存入那个存入另一个变量x中,输出那个变量。

需注意p要赋初值的地方与x不同。

源代码如下:

 1 #include<iostream>
 2 #include<string>
 3 #define max 100
 4 using namespace std;
 5 int main()
 6 {
 7     int n,i,j,x=0,p;
 8     string a[max];
 9     cin>>n;
10     for(i=0;i<n;i++)
11             cin>>a[i];
12     for(i=0;i<n;i++)
13     {
14         p=0;
15         for(j=i;j<n;j++)
16         {
17             if(a[i]==a[j])
18                 p++;
19         }
20         if(p>x)
21             x=p;
22     }
23     cout<<x<<endl;
24     return 0;
25 }
时间: 2024-10-17 22:40:49

Ohana Cleans Up0101的相关文章

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

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

#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节点来创建集群,或者用官网提供的启动脚本.这些守护进程也可以只在一台机器上以便