题目的大意是,给你 m 个数字,让你从中选 n 个,使得选出的数字的极差最小。

  好吧,超级大水题。因为要极差最小,所以当然想到要排个序咯,然后去连续的 n 个数字,因为数据不大,所以排完序之后直接暴力就OK了。

附AC代码:

#include <stdio.h>
#include <math.h>
#include <iostream>
#include <cstdarg>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <list>
#include <vector>
#include <map>
long
sizeof(a))
namespace std;
  15:  
int count, ...)
  17: {
  18:     va_list arg_ptr;
  19:     va_start (arg_ptr, count);
int i = 0; i < count; i++)
char*));
  22:     va_end(arg_ptr);
  23: }
  24:  
int buf[59];
  26:  
int main()
  28: {
int n, m;
, &n, &m))
  31:     {
  32:         Clean(1, buf);
int i = 0; i < m; i++)
, &buf[i]);
  35:         sort(buf, buf + m);
int res = 999999;
int i = n - 1; i < m; i++)
  38:             res = min(res, (buf[i] - buf[i - n + 1]));
, res);
  40:     }
return 0;
  42: }

相关文章:

  • 2021-12-22
  • 2021-11-19
  • 2022-01-09
  • 2021-08-04
  • 2021-11-25
  • 2021-11-26
  • 2021-10-04
  • 2022-02-08
猜你喜欢
  • 2021-09-20
  • 2021-12-02
  • 2021-06-27
  • 2021-06-03
  • 2021-12-19
  • 2021-09-01
  • 2021-09-24
相关资源
相似解决方案