题目的大意是,给你 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: }

A. Puzzles CodeForces Round #196 (Div.2)的更多相关文章

  1. Codeforces Round #196 (Div. 2) A. Puzzles 水题

    A. Puzzles Time Limit: 2 Sec  Memory Limit: 60 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem ...

  2. Codeforces Round #196 (Div. 2) D. Book of Evil 树形dp

    题目链接: http://codeforces.com/problemset/problem/337/D D. Book of Evil time limit per test2 secondsmem ...

  3. Codeforces Round #196 (Div. 1) 题解

    (CF唯一不好的地方就是时差……不过还好没去考,考的话就等着滚回Div. 2了……) A - Quiz 裸的贪心,不过要用矩阵乘法优化或者直接推通式然后快速幂.不过本傻叉做的时候脑子一片混乱,导致WA ...

  4. Codeforces Round #196 (Div. 1 + Div. 2)

    A. Puzzles 对\(f[]\)排序,取连续的\(m\)个. B. Routine Problem 考虑\(\frac{a}{b}\)和\(\frac{c}{d}\)的大小关系,适配后就是分数的 ...

  5. D. Puzzles(Codeforces Round #362 (Div. 2))

    D. Puzzles Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 ...

  6. Codeforces Round #196 (Div. 2) B. Routine Problem

    screen 尺寸为a:b video 尺寸为 c:d 如果a == c 则 面积比为 cd/ab=ad/cb (ad < cb) 如果b == d 则 面积比为 cd/ab=cb/ad  (c ...

  7. Codeforces Round #196 (Div. 2)

    A 题意:O(-1) 思路:排个序搞定. B 题意:O(-1) 思路:坑了我好久,这个框框水平垂直比例固定,分两种情况即可,不能旋转,我想多了,分了四种情况. C 题意:一列n个位置,让你填m个数,当 ...

  8. Codeforces Round #196 (Div. 2) 少部分题解

    A:sort以后求差值最小 ]; int main() { int n,m; cin>>n>>m; ; i < m ; i++) cin>>a[i]; sor ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. 使用var声明的变量 和 直接赋值并未声明的变量的区别

    在看JS高级程序设计时忽然想到这个问题,众所周知,直接赋值一个变量而为声明,会产生一个全局变量(或者说是全局对象的属性),但用var声明的变量 和 直接赋值而并未声明的变量 都有哪些区别呢,这是我在百 ...

  2. html + css + js注释规范

    添加注释到代码中,是一个很好的习惯,而且极大的提高了代码的可读性 1.HTML <!--commentContent--> 2.CSS //commentContent /*comment ...

  3. 浏览器的CSS各种hack,大汇总

    对着IE久了也有感觉了,在win10出新浏览器以及中国的IE6+用户没有普及新的浏览器前IE还是个坑,所以hack这东西还是要掌握一点的.不废话直接贴图 记得之前在项目里面针对IE6的hack是这样写 ...

  4. APM (应用性能管理)

    在信息科学和系统控制领域,APM是用来监控和管理应用软件是否有效运行的.APM通过监测和分析应用的表现去保证软件应用的良好运行,APM已经商用. 基本定义 APM = Application Perf ...

  5. Android笔记——四大组件详解与总结

     android四大组件分别为activity.service.content provider.broadcast receiver. ------------------------------- ...

  6. PageLayoutControl的基本操作

    整理了下对PageLayoutControl的基本功能操作 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2 ...

  7. linux 操作系统下c语言编程入门

    2)Linux程序设计入门--进程介绍 3)Linux程序设计入门--文件操作 4)Linux程序设计入门--时间概念 5)Linux程序设计入门--信号处理 6)Linux程序设计入门--消息管理  ...

  8. JVM垃圾回收机制总结(7) :调优方法

    JVM调优工具 Jconsole,jProfile,VisualVM Jconsole : jdk自带,功能简单,但是可以在系统有一定负荷的情况下使用.对垃圾回收算法有很详细的跟踪.详细说明参考这里 ...

  9. 280. Wiggle Sort

    题目: Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] ...

  10. PHP 简介

    lamp LAMP - Linux Apache MySQL PHP MySQL - 三个层次:文件层次,服务层次,界面层次. LAMP-Linux Apache MySQL PHP 本机 :127. ...