2021-03-01

找不到错误在哪,求

蓝桥杯历届真题 对局匹配

#include<bits/stdc++.h>
using namespace std;

struct node
{
	int val;
	int sum;
}e[100005];

int main()
{
	int n, k;
	int t;
	int box[100005] = {0};
	int f[100005] = {0};
	cin >> n >> k;
	int mx = 0;
	for(int i = 0 ; i < n ; i ++)
	{
		cin >> t;
		box[t]++;
		mx = max(mx , t);
	}	
	
	if(k == 0)
	{
		int ans = 0;
		for(int i = 1 ; i <= mx ; i ++)
			if(box[i])ans ++;
		cout << ans;
	}
	else
	{
		int z = 1;
		for(int i = 1 ; i <= mx ; i ++)
		{
			if(box[i])
			{
				int m = i;
				while(m <= 100000 && box[m])
				{
					e[z].val = m;
					e[z ++].sum = box[m];
					box[m] = 0;
					m += k;
				}
			}
		}
		
		//for(int i = 1 ; i < z; i ++)
		//	cout << e[i].val << " : " << e[i].sum <<endl;
		f[1] = e[1].sum;
		for(int i = 2 ; i < z; i ++)
		{
			if(e[i].val - e[i - 1].val == k)
				f[i] = max(f[i - 1] , f[i - 2] + e[i].sum);
			else 
				f[i] = f[i - 1] + e[i].sum;	
		//	cout << i << " : " << f[i] << endl;
		}
		cout << f[z - 1];
	}
} 
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页