Codeforces Round #196 (Div. 2) A. Puzzles 水题
A. Puzzles
Time Limit: 2 Sec Memory Limit: 60 MB
题目连接
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373
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
Output
Sample Input
4 6
10 12 10 7 5 22
Sample Output
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.
题意
给你N个数,然后让你选M个,让这M个数中的最大值减去最小值的这个值,最小
问这个最小值是多少
题解:
拍一下序,然后暴力搞一搞就好
代码:
//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>
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 maxn 2001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/* */
//**************************************************************************************
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int a[maxn];
bool cmp(int c,int d)
{
return c>d;
}
int main()
{
int n=read(),m=read();
for(int i=;i<m;i++)
a[i]=read();
int mi=inf;
sort(a,a+m,cmp);
for(int i=;i+n-<m;i++)
mi=min(a[i]-a[i+n-],mi);
printf("%d\n",mi);
}
Codeforces Round #196 (Div. 2) A. Puzzles 水题的更多相关文章
- Codeforces Round #185 (Div. 2) B. Archer 水题
B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...
- Codeforces Round #360 (Div. 2) A. Opponents 水题
A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...
- Codeforces Round #190 (Div. 2) 水果俩水题
后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...
- Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告
对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...
- Codeforces Round #340 (Div. 2) B. Chocolate 水题
B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...
- Codeforces Round #340 (Div. 2) A. Elephant 水题
A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...
- Codeforces Round #340 (Div. 2) D. Polyline 水题
D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...
- Codeforces Round #338 (Div. 2) A. Bulbs 水题
A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...
- Codeforces Round #282 (Div. 1) A. Treasure 水题
A. Treasure Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/494/problem/A ...
随机推荐
- gcc -O0 -O1 -O2 -O3 四级优化选项及每级分别做什么优化【转】
转自:http://blog.csdn.net/qinrenzhi/article/details/78334677 相关博客http://blog.chinaunix.net/uid-2495495 ...
- shell监控网站是否自动运行并自动重启【原创】
shell监控网站是否自动运行并自动重启 #!/bin/bash -T www.baidu.com ];then echo "`date` 网站访问正常!" >> /r ...
- http请求中的中文乱码问题
通过浏览器访问服务器页面和资源时,不可避免地要传送中文字串,如果客户机与服务器不能用同一码表解析字串,肯定会出现各种各样的乱码问题.我总结了几个乱码场景及解决办法,如下 1.服务器上的中文字串被客户端 ...
- SQL Server和Access数据读写
1.查询Access中数据的方法: select * from OpenRowSet('microsoft.jet.oledb.4.0',';database=c:/db2.mdb','select ...
- PostgreSQL数据库如果不存在则插入,存在则更新
INSERT INTO UM_CUSTOMER(customercode,CompanyFlag,InputTime,LocalVersion) ) ON conflict(customercode) ...
- PHP 识别 java 8位 des 加密和 解密方式
代码及使用说明: <?php /** *PHP 识别 java 8位密钥的加密和解密方式 *@desc 加密方式 通用 */ class DES { var $key; var $iv; //偏 ...
- 【LOJ】#2026. 「JLOI / SHOI2016」成绩比较
题解 用\(f[i][j]\)表示考虑了前i个排名有j个人被碾压 \(f[i][j] = f[i - 1][k] \* C[k][j] \* C[N - k - 1][N - r[i] - j] \* ...
- 【LOJ】 #2545. 「JXOI2018」守卫
题解 只会蠢蠢的\(n^3\)--菜啊-- 我们发现最右的端点一定会选,看到的点一定是当前能看到的斜率最小的点变得更小一点,记录下这个点,在我们遇到一个看不到的点的时候,然后只用考虑R到它斜率最小的这 ...
- Django实战(12):增加目录页,设定统一布局
针对上一节的新需求,界面设计师还为我们设计了一个新的界面,不仅仅是目录页,还包含了站点的整体风格,如下图: 感谢界面设计师为我们提供的“又黑又硬”的工具条,这个看起来真的很酷.下面,让我们来享用她的工 ...
- webstorm for ubuntu install
1. from https://www.tslang.cn/index.html#download-links downloading https://www.jetbrains.com/webst ...