A. Puzzles CodeForces Round #196 (Div.2)

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

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

附AC代码:

   1: #include <stdio.h>
   2: #include <math.h>
   3: #include <iostream>
   4: #include <cstdarg>
   5: #include <algorithm>
   6: #include <string.h>
   7: #include <stdlib.h>
   8: #include <string>
   9: #include <list>
  10: #include <vector>
  11: #include <map>
  12: #define LL long long
  13: #define M(a) memset(a, 0, sizeof(a))
  14: using namespace std;
  15:  
  16: void Clean(int count, ...)
  17: {
  18:     va_list arg_ptr;
  19:     va_start (arg_ptr, count);
  20:     for (int i = 0; i < count; i++)
  21:         M(va_arg(arg_ptr, char*));
  22:     va_end(arg_ptr);
  23: }
  24:  
  25: int buf[59];
  26:  
  27: int main()
  28: {
  29:     int n, m;
  30:     while (~scanf("%d%d", &n, &m))
  31:     {
  32:         Clean(1, buf);
  33:         for (int i = 0; i < m; i++)
  34:             scanf("%d", &buf[i]);
  35:         sort(buf, buf + m);
  36:         int res = 999999;
  37:         for (int i = n - 1; i < m; i++)
  38:             res = min(res, (buf[i] - buf[i - n + 1]));
  39:         printf("%d\n", res);
  40:     }
  41:     return 0;
  42: }
posted @ 2013-08-19 15:16  ~無痕~  阅读(236)  评论(0编辑  收藏  举报