#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<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define me(s) memset(s,0,sizeof(s))
#define For(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz size
#define clr clear
#define F(a,b) for(int i=a;b;i++)

int n;
const int N=110;
int vis[N][N];

int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
        {
            char s[N];
            scanf("%s",s);
            for(int j=0;j<n;j++)
                vis[i][j]=s[j]-'0';
        }
        int mark[N];
        int cnt=0;
        me(mark);
        int maxl=0;//维护找到的相同行的最大值
        for(int i=0;i<n;i++)//枚举每一行
            if(!mark[i])
            {
                mark[i]=++cnt;//mark[i]表示第i行是第mark[i]种不同的行
                int num=1;//统计和第i行完全相同的行的个数
                for(int j=i+1;j<n;j++)
                   {
                       int flag=1;
                       for(int k=0;k<n;k++)
                        if(vis[j][k]!=vis[i][k])
                       {
                           flag=0;break;
                       }
                       if(flag)
                       {
                           mark[j]=cnt;num++;
                       }
                   }
                maxl=max(maxl,num);//更新最大值
            }
    printf("%d\n",maxl);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-29 19:10:28

#309 (div.2) B. Ohana Cleans Up的相关文章

贪心 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

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) A. Kyoya and Photobooks

题目传送门 1 /* 2 找规律,水 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 using namespace std; 10 11 const int MAXN = 1e4 + 10; 12 const int INF = 0x3f3f3f3f; 13 char s

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

Codeforces Round #309 (Div. 2) C

题意: 就是给出总共有k种颜色,每种颜色有ki种,排列必须满足第i+1种的最后一种颜色必须在第i种最后一种颜色的后面,其他颜色随意.总共有多少种排列点的方法. 分析: 假设d[i]表示前i种的排列的数量,那么第i+1种的数量就是d[i]*C(a[1]+a[2]+..a[i+1]-1,a[i+1]-1);预先处理好排列组合数就好了,直接计算. ps:CF的比赛时间还真是有点烦,话说我一直不明白为什么我看电视能坚持到两点,打CF就不行呢?于是我就边看电视边打CF~哈哈哈哈 #include <cst

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