• codeforces 377A. Puzzles 水题


    A. Puzzles

    Time Limit: 20 Sec  Memory Limit: 256 MB

    题目连接

    http://codeforces.com/problemset/problem/337/A

    Description

    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

    4 6
    10 12 10 7 5 22

    Sample Output

    5

    HINT

    题意

     让你找到n块拼图,使得最大值剪最小值最小

    题解:

    排个序就好了

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)  
    #define maxn 200001
    #define mod 10007
    #define eps 1e-9
    int Num;
    char CH[20];
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    //**************************************************************************************
    
    int a[maxn];
    int main()
    {
        //test;
        int n=read(),m=read();
        swap(n,m);
        for(int i=0;i<n;i++)
            a[i]=read();
        sort(a,a+n);
        int ans=inf;
        for(int i=0;i+m-1<n;i++)
        {
            ans=min(ans,a[i+m-1]-a[i]);
        }
        cout<<ans<<endl;
        
    }
  • 相关阅读:
    30 分钟快速入门 Docker 教程
    python functools.wraps
    计算机科学中最重要的32个算法
    JDBC的作用及重要接口
    SSO单点登录--支持C-S和B-S
    谈谈Sql server 的1433端口
    屏蔽:粘贴到KindEditor里,IE下弹出框报”对象不支持moveToElementText属性或方法“错误的提示
    markdown
    ddd
    python进阶学习(一)--多线程编程
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4547483.html
Copyright © 2020-2023  润新知