Codeforces Round #196 (Div. 2) / 337A Puzzles (搜索)

Algorithmic puzzles(算法谜题).pdf 书中提供了150道关于算法的趣题,并有详细讲解。 立即下载

A. Puzzles
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 integersf1, 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 test(s)
input
4 6
10 12 10 7 5 22
output
5

排序,然后从小到大求最小的差即可。


完整代码:

/*30ms,0KB*/

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

int main(void)
{
	int n, m, min, temp;
	scanf("%d%d", &n, &m);
	int f[m + 1];
	for (int i = 1; i <= m; ++i)
		scanf("%d", &f[i]);
	sort(f + 1, f + m + 1);
	min = f[n] - f[1];
	for (int i = n + 1; i <= m; ++i)
	{
		temp = f[i] - f[i - n + 1];
		if (temp < min)
			min = temp;
	}
	printf("%d", min);
	return 0;
}



Puzzles:各种编程谜题的集合 这个 repo 包含个人解决方案和各种编程练习的尝试。 包括: Yodle的JuggleFest Groupon 的欺诈检测(为 CodeSprint 2 完成,InterviewStreet 举办) Spotify 的三态内存(代码挑战) Spotify 的 Troll 问题(代码挑战) 立即下载

相关推荐

NI-HIL学习开篇

自我介绍下,四年零部件厂工作经验,一年(至今)主机厂工作经验,负责BMS/VCU方向软硬件测试。 学习目的:把握新能源汽车的测试发展趋势,顺应历史的洪流。 学习目标:1.掌握HIL开发测试流程中的IO配置、开环验证、闭环模型开发及调试、自动化测试 2.掌握第三方模型的搭建及simulink关联仿真(2019.05.21新增:需巩固练习matlab基础——2...

masonson的专栏 4185

CF337A Maze 解题报告

codeforces搜索解题报告

weixin_60849605的博客 214

LTspice 导入 PSpice 模型实战指南 --(解决语法兼容性与模型优化问题)

本文提供了将PSpice模型成功导入LTspice的详细实战指南。针对两者间的语法兼容性问题,文章以TI UCC23513为例,逐步讲解模型获取、符号创建、常见语法错误修改及仿真验证方法,并分享了模型优化与个人库管理技巧,帮助用户高效解决模型导入与仿真难题。

weixin_28278377的博客 861

Codeforces Round #196 (Div. 2)

A. Puzzles time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The end of the school year is near and Ms. Manana

bo-jwolf的专栏 1145

SPEI计算避坑指南:gma中Distribution和FitMethod参数怎么选?

本文深入探讨了在SPEI计算中如何科学选择gma库中的Distribution和FitMethod参数,帮助研究者避开常见陷阱。详细分析了LogLogistic、Gamma和Pearson3三种分布的适用场景,以及LMoment与MLE拟合方法的优缺点,为气象干旱研究提供实用指南。

weixin_30308101的博客 256

【Visual Assist X助手安装问题】Visual Assist X无法安装(双击安装包没反应) | Visual Assist X安装后在Visual Studio中找不到(亲测有效)

本文分享了Visual Assisant X助手的安装与使用问题的详细解决办法,因为网上搜集的信息比较少,所以有一定的参考价值。考虑到很多开发新手会遇到上述问题,可能对Windows系统不熟悉,所以相关操作步骤讲解的很详细!

dvlinker的技术专栏 6万+

Problem-337A-Codeforces--Puzzles

A. Puzzles time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output The end of the school year is near and Ms. Manana, the teacher,

qq_36667106的博客 464

复现论文《Analysis of circulating current mechanism of Grid-forming offshore wind farm based on DRU-HVDC》

该论文研究了基于二极管整流单元(DRU)和低频交流(LFAC)输电的构网型(GFM)海上风电场并网系统中环流的产生机理。由于 DRU 不可控,系统电压与频率依赖于风力发电机(WT)的网侧变流器,当多台 WT 并联运行时,因输出电压幅值、相位、输出阻抗或频率不匹配,会产生基频环流,导致系统损耗增加与稳定性下降。论文通过理论建模与 MATLAB/Simulink 仿真,分析了四种不平衡工况下的环流机理,并指出幅值不平衡和阻抗不平衡引起无功环流,相位不平衡引起有功环流,频率不平衡则引起环流振荡,为后续环流抑制研究

huanghm88的专栏 115

C

C - Puzzles Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 337A Description The end of the school year is near and Ms. 

袁汉春 633

C# 上位机 YOLO 实战:从数据采集到目标识别的全流程拆解

本文以工业螺栓缺陷检测为例,完整拆解了C#上位机+YOLO从数据采集到目标识别的全流程。数据采集:保证图像质量,线程安全采集,必要时归档数据;预处理:适配YOLO模型输入格式,复用对象减少内存开销;推理解析:正确解析张量结果,过滤低置信度目标;落地环节:可视化展示结果,实现工业交互和日志记录。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1465

maya导入导出bvh 自动 脚本

maya打开bvh脚本

jacke121的专栏 1558

CodeForces -337A:Puzzles(水)

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 p

并非所有流浪者都迷失了自我 945

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Round #196(Div.2)A 、Puzzles

题目链接:http://codeforces.com/contest/337/problem/A 1、首先对所有m个数字排序,每次枚举连续n个数,求首位差的最小值。 #include #include #include using namespace std; int a[55]; int ans=2147483647; int main(){    int n,m;    w

351

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

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

A. Puzzles time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The end of the school year is near and Ms. Manana

jjaw2013 735

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

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. Mana...

weixin_33795833的博客 205

codeforces 337A

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 the

woshigaoniuniu的博客 384

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 hav...

weixin_33739627的博客 177

CF#196DIV2:A-Puzzles

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

ACM!荣耀之路! 2464

CF 337A (13.08.22)

A. Puzzles time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The end of the school year is near and Ms. Manana, th...

445822357 141

codeforces 337A(Puzzles) Java

import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io

TinyDolphin的博客 438

-Puzzles

C - Puzzles Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 337A Description

读不懂的流年 630

Puzzle

A children's puzzle that was popular 30 years ago consisted of a 5  5 frame which contained 24 small squares of equal size. A unique letter of the alphabet was printed on each small square.

Rookie的博客 474

【cf 1108 C】枚举一下排列

1.题目链接。题目大意,给定一个字符串,这些字符串只有三种字符,“RGB”。可以改变一些位置的字符,使得同一种字符之间下标之间的距离是3的倍数。问最小需要改变的数量和最终改变好的字符串。 2.分析一下可知,最后的字符串一定是RGB的某种排列的n倍延申。所以我们枚举一下排列,统计一下哪一种排列吻合的最好即可。 #include <bits/stdc++.h> using names...

YG爱木木 340

CF543B Destroying Roads(bfs+枚举)

因为边权都是1,所以可以bfs求得两点间最短路O(nm)O(nm)。然后考虑两条最短路如果不想交,则答案显然就是m-dis[s1][t1]-dis[s2][t2]。如果相交呢,那他们一定会有一段重合的,这样答案显然有可能更小,而且这样的情况下,只有可能在重合的两端分开,分开后就不可能再重合了。我们枚举这段重合的起点和终点i,j,判断是否合法,然后更新答案。注意:要把s1和t1交换一下,因为一共有四种

Icefox的博客 524
上一篇: Codeforces Round #196 (Div. 2) / 337B Routine Problem(数学)
下一篇: Codeforces Round #196 (Div. 2) / 337C Quiz (贪心&快速幂取模)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址