cf#309-B. Ohana Cleans Up-排序水题

题意,给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;
	
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值