简单题
Description
给出一个长度为n的数列,求最少删除几个数可以让剩下的数中 最大值-最小值<=m
Input
第一行输入两个数n,m(1≤n≤100,0≤m≤100)
第二行有n个数(0≤xi≤100)
ps:本题为多组输入
Output
输出所求答案
Sample Input 1
3 1 2 1 4
Sample Output 1
1
Sample Input 2
3 0 7 7 7
Sample Output 2
0
Sample Input 3
6 3 1 3 4 6 9 10
Sample Output 3
3
Hint
解释:
样例1可以删除4
样例2不用删除
样例3删除1,9,10,此时剩下3,4,6满足题意
让每个数字都先取余m,那么符合这样的关系的数字一定是相等的,
然后在这n个数字中,能否找到找k个相同的数字,找到为Yes,反之No
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<vector>
#include<stack>
using namespace std;
#define inf 0x3fffffff
#define LL long long
map<int,int>ma;
int main()
{
int n,k,m,a;
while(~scanf("%d%d%d",&n,&k,&m))
{
ma.clear();
int flag=0;
while(n--)
{
scanf("%d",&a);
if(flag) continue;
if(++ma[a%m]>=k) flag=1;
}
if(flag)printf("Yes\n");
else printf("No\n");
}
}