cf#345-B - Beautiful Paintings-暴力

102 篇文章 0 订阅
37 篇文章 0 订阅

http://codeforces.com/contest/651/problem/B


给n个数,问怎么排列重组后,能找出最多的 合法对

合法对的意思是:  ai +1 > ai         


  也就是排在后面的数要比前面的大,就算一对(必须相邻)

n=1000,

数的大小也只有1000

直接排序n^2无脑暴力模拟这个过程:

把数据映射到hash数组,每次遍历hash数组,这样的遍历一定是按从小到大的,那么每次得到一个 递增序列,他的长度-1就是我们要求的答案。累加


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;

const double pi=acos(-1.0);
double eps=0.000001;
int vis[1005]; 
int main()
{
	
	int n;
	cin>>n;
	int i,j,tmp;
	for (i=1;i<=n;i++)
	{
		scanf("%d",&tmp);
		vis[tmp]++;
	}
	int maxx=0;
	for (i=1;i<=1000;i++)
	{
		int cun=0;
		for (j=1;j<=1000;j++)
		{
			if (vis[j]) 
			{
				vis[j]--;
				cun++;
			}
		}
		if (cun>0)
		maxx+=cun-1;
	}
	printf ("%d\n",maxx);
	
	
	
	
	
	
	
	
	
	return 0;
	
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值