A. Card Exchange.

原题链接

题解

1.如果一开始没有 \(k\) 个相同的卡片,答案是 \(n\)
2.否则将按照如下步骤

  • \(k\) 个相同卡片
  • 如果取出卡片后,没有剩余卡片了,随便放 \(k-1\) 个卡片进去,游戏结束
  • 否则把 \(k-1\) 个卡片全部变成剩余卡片中的一个,情况回到第一个步骤

code

#include<bits/stdc++.h>
using namespace std;
const int N=105;
int a[N];
int main(){
//	freopen("input.txt","r",stdin);
	int t;
	cin>>t;
	while (t--){
		int n,k;
		map<int ,int > map1;
		cin>>n>>k;
		int MAX=0;
		for (int i=1;i<=n;i++){
			int x;
			cin>>x;
			map1[x]++;
			if (map1[x]>MAX) MAX=map1[x];
		}
		if (MAX>=k) cout<<k-1<<endl;
		else cout<<n<<endl;
	}	
	return 0;
}
posted @ 2024-04-28 22:12  纯粹的  阅读(25)  评论(0)    收藏  举报