zoukankan      html  css  js  c++  java
  • CodeForces 337A Puzzles

    Puzzles

    Time Limit: 1000ms
    Memory Limit: 262144KB
    This problem will be judged on CodeForces. Original ID: 337A
    64-bit integer IO format: %I64d      Java class name: (Any)
    The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).

    The shop assistant told the teacher that there are m puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of f1 pieces, the second one consists of f2 pieces and so on.

    Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let A be the number of pieces in the largest puzzle that the teacher buys and B be the number of pieces in the smallest such puzzle. She wants to choose such n puzzles that A - B is minimum possible. Help the teacher and find the least possible value of A - B.

    Input

    The first line contains space-separated integers n and m (2 ≤ n ≤ m ≤ 50). The second line contains m space-separated integers f1, f2, ..., fm (4 ≤ fi ≤ 1000) — the quantities of pieces in the puzzles sold in the shop.

     

    Output

    Print a single integer — the least possible difference the teacher can obtain.

     

    Sample Input

    Input
    4 6
    10 12 10 7 5 22
    Output
    5

    Hint

    Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.

     

    Source

     
    解题:一道傻逼题。。
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 100;
     4 int d[maxn],n,m;
     5 int main() {
     6     scanf("%d %d",&n,&m);
     7     for(int i = 0; i < m; ++i)
     8         scanf("%d",d+i);
     9     sort(d,d+m);
    10     int ret = INT_MAX;
    11     for(int i = 0 + n - 1; i < m; ++i)
    12         ret = min(ret,d[i] - d[i-n+1]);
    13     printf("%d
    ",ret);
    14     return 0;
    15 }
    View Code
  • 相关阅读:
    错误解决记录-------------验证启动HDFS时遇到的错误
    Spark环境搭建(一)-----------HDFS分布式文件系统搭建
    Synergy简单使用小记
    python基础一 ------排序和查找算法
    Scrapy基础(十四)————Scrapy实现知乎模拟登陆
    Scrapy基础(十四)————知乎模拟登陆
    Scrapy基础(十三)————ItemLoader的简单使用
    Scrapy基础(十二)————异步导出Item数据到Mysql中
    简单python爬虫练习 E站本爬取
    7-4 jmu-Java&Python-统计文字中的单词数量并按出现次数排序 (25分)
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4617148.html
Copyright © 2011-2022 走看看