题意,给n*n个0 1 矩阵,不限制操作次数,每次操作 翻转 整一列,问最后 最多能使得多少行同时为1
。。肯定是开始就完全相等的行,最后才能变成一样。。。
直接sort一下,,找重复次数最多的。。。
ps:....写sort的cmp函数手抖了一下 写成
int cmp(node a,node b)
{
return strcmp(a.s,b.s)<=0;
}
RE了几次。。。。
后来查到原因是 标准要求 std::sort 的比较仿函数定义严格弱序(strict weak ordering),
Effecitve STL 中第 21条: 永远让比较函数对相同元素返回false
std的sort函数用的是QuickSort算法,采用分段递归排序。很可能是在递归实现的时候出现问题
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
char **s;
struct node
{
char s[105];
};
int cmp(node a,node b)
{
return strcmp(a.s,b.s)<0;
}
node ss[105];
int main()
{
int i,n;
scanf("%d",&n);
getchar();
for (i=1;i<=n;i++)
{
scanf("%s",ss[i].s);
}
sort(ss+1,ss+1+n,cmp);
int maxx=0;
int tmp=0;
for (i=1;i<n;i++)
{
if (strcmp(ss[i].s,ss[i+1].s)==0)
{
tmp++;
}
else
{
if (tmp>maxx)
maxx=tmp;
tmp=0;
}
}
if (tmp>maxx)
maxx=tmp;
printf("%d\n",maxx+1);
return 0;
}