A. Puzzles CodeForces Round #196 (Div.2)
题目的大意是,给你 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)的更多相关文章
- Codeforces Round #196 (Div. 2) A. Puzzles 水题
A. Puzzles Time Limit: 2 Sec Memory Limit: 60 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem ...
- 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 ...
- Codeforces Round #196 (Div. 1) 题解
(CF唯一不好的地方就是时差……不过还好没去考,考的话就等着滚回Div. 2了……) A - Quiz 裸的贪心,不过要用矩阵乘法优化或者直接推通式然后快速幂.不过本傻叉做的时候脑子一片混乱,导致WA ...
- Codeforces Round #196 (Div. 1 + Div. 2)
A. Puzzles 对\(f[]\)排序,取连续的\(m\)个. B. Routine Problem 考虑\(\frac{a}{b}\)和\(\frac{c}{d}\)的大小关系,适配后就是分数的 ...
- 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 ...
- 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 ...
- Codeforces Round #196 (Div. 2)
A 题意:O(-1) 思路:排个序搞定. B 题意:O(-1) 思路:坑了我好久,这个框框水平垂直比例固定,分两种情况即可,不能旋转,我想多了,分了四种情况. C 题意:一列n个位置,让你填m个数,当 ...
- Codeforces Round #196 (Div. 2) 少部分题解
A:sort以后求差值最小 ]; int main() { int n,m; cin>>n>>m; ; i < m ; i++) cin>>a[i]; sor ...
- 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 ...
随机推荐
- 546A. Soldier and Bananas
等差数列: 以k为首相,k为公差,w个数量的和与n的大小关系 输出max(sum-0,0) Java程序 import java.util.Scanner; public class A546 ...
- copy_to_user,copy_from_user,get_user,put_user函数比较
copy_to_user,copy_from_user,get_user,put_user函数比较 copy_to_user -- Copy a block of data into user sp ...
- iOS开发--storyboard适配pin
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-007UserTypes的用法(@org.hibernate.annotations.Type、@org.hibernate.annotations.TypeDefs、CompositeUserType、DynamicParameterizedType、、、)
一.结构 二.Hibernate支持的UserTypes接口 UserType —You can transform values by interacting with the plain JD ...
- Struts2笔记——第一个实例HelloWorld
1.创建新的Dynamic Web项目 ------------------------------------------ 2.struts2框架配置 ------------------- ...
- [转]应聘Java,jsp,j2ee软件工程师笔试中可能出现的问题
相信大家应聘的时候第一关就是笔试,即使是一位很有经验的工程师也不一定能够顺利通过,笔试不好,可能就无法进行面试,即使能够进行面试,考官对你的印象也不会很好,问的问题也会很多,估计很难吃的消,当然如果你 ...
- ITEM 2 MAC OSX 功能略强大的终端
iTerm2 iTerm 2 is a terminal emulator for Mac OS X that does amazing things. iTerm2 是一个终端模拟器,官方网站:ht ...
- 高通/苹果/联发科:手机CPU那些事
如今人们买手机,都比较关心采用了什么CPU,因为CPU直接决定了这台手机的性能,CPU之于手机就好比人的大脑,它是整台手机的控制中枢系统,也是逻辑部分的控制中心.又相当于车的发动机,发动机越强劲,车子 ...
- linux下安装配置DHCP服务器
前提是已经安装了 core 及 base 两个组 1 2 3 4 5 # cat /etc/redhat-release Red Hat Enterprise Linux Server relea ...
- .NET中使用OleDb读取Excel
在.NET中可以用OleDb(Object linking and embeding DataBase)来访问Excel using System; using System.Data; using ...