syu问题 C: 游戏预测

版权声明:转载请注明出处 https://blog.csdn.net/qq_41431457/article/details/88368780

题目描述

  有M个人,每一个人有N张牌,每轮中牌面最大的人赢,(牌面只可能是1~M*N中的一个数且不重复),给出一个人的牌,求其至少能够赢的局数。

  (注:每轮比较之后需要把牌扔下)

输入

第一行输入一个整数T,表示数据组数(1<T<10000);

第二行输出两个整数M和N,表示人数和这个人手中拥有的牌的张数(2<=M<=20、1<=N<=50);

第三行输入N个整数,表示这个人N张牌每张牌的大小;

输出

对于每组数据,输出结果。

样例输入

2
2 5
1 7 2 10 9
6 11
62 63 54 66 65 61 57 56 50 53 48

样例输出

2
4

倒序遍历,如果这张牌有的话,就便利,如果没有就需要出最大的牌抵消,就是max-=2;

#include<bits/stdc++.h>
using namespace std;
int have[2005];
int main()
{
	int test;
	cin>>test;
	while(test--)
	{
		memset(have,0,sizeof(have));
		int n,m,ans=0;
		cin>>n>>m;
		for(int i=0;i<m;i++)	cin>>have[i];
		
		sort(have,have+m);
		int max=n*m;
		for(int i=m-1;i>=0;i--)
		if(have[i]==max)
		{
			max--;
			ans++;
		}
		else max-=2;
		cout<<ans<<endl;
	}
	return  0;
	
}
/*
7 11
62 63 54 66 65 61 57 56 50 53 48
*/








猜你喜欢

转载自blog.csdn.net/qq_41431457/article/details/88368780