[Codeforces 863B]Kayaking
Description
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·n people in the group (including Vadim), and they have exactly n - 1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. i-th person's weight is wi, and weight is an important matter in kayaking — if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash.
Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks.
Help the party to determine minimum possible total instability!
Input
The first line contains one number n (2 ≤ n ≤ 50).
The second line contains 2·n integer numbers w1, w2, ..., w2n, where wi is weight of person i (1 ≤ wi ≤ 1000).
Output
Print minimum possible total instability.
Sample Input
21 2 3 4
Sample Output
1
题解
在长度为$2*n$的数列中挑出两个数,使剩下的数两两配对差值和最小。
如果不挑出,贪心的思想,显然按原数组排序就可以找到。
考虑$n$很小,我们暴力枚举挑出的数,把剩下的排序即可。
I think there is no need to tell you how to solve this problem...
//It is made by Awson on 2017.9.30 #include <set> #include <map> #include <cmath> #include <ctime> #include <queue> #include <stack> #include <vector> #include <cstdio> #include <string> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL long long #define Min(a, b) ((a) < (b) ? (a) : (b)) #define Max(a, b) ((a) > (b) ? (a) : (b)) using namespace std; void read(int &x) { ; ); ch = getchar()); ; isdigit(ch); x = (x<<)+(x<<)+ch-, ch = getchar()); x *= -*flag; } ], n; ]; void work() { read(n); n <<= ; ; ; i <= n; i++) read(w[i]); ; i < n; i++) ; j <= n; j++) { ; ; k <= n; k++) if (k!=i && k!= j) sorted[++top] = w[k]; sort(sorted+, sorted++top); ; ; i <= top; i += ) cnt += sorted[i+]-sorted[i]; ans = Min(ans, cnt); } printf("%d\n", ans); } int main() { work(); ; }
[Codeforces 863B]Kayaking的更多相关文章
- Educational Codeforces Round 29
A. Quasi-palindrome 题目链接:http://codeforces.com/contest/863/problem/A 题目意思:问一个数可不可以在不上一些前缀0以后变成一个回文数. ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- java 中的JDK封装的数据结构和算法解析(集合类)----顺序表 List 之 ArrayList
1. 数据结构之List (java:接口)[由于是分析原理,这里多用截图说明] List是集合类中的容器之一,其定义如下:(无序可重复) An ordered collection (also kn ...
- Numpy - 多维数组(上)
一.实验说明 numpy 包为 Python 提供了高性能的向量,矩阵以及高阶数据结构.由于它们是由 C 和 Fortran 实现的,所以在操作向量与矩阵时性能非常优越. 1. 环境登录 无需密码自动 ...
- vim配置之taglist插件安装
上次说了不带插件的vim配置,今天补充两个,来日方长,不定期更新: 首先看一个路径: 下载ctags,将其中的ctags.exe复制到上边目录下边: 地址:https://sourceforge.ne ...
- iOS开发-OC中TabView的编辑
UITableView编辑 1> UITableView 编辑流程 2> UITableView 编辑步骤(四步) ① 第一步 : 让 TableView 处于编辑状态(在按钮点击事件方法 ...
- 【iOS】OC-Quartz2D简单使用
什么是Quartz2D Quartz 2D是一个二维绘图引擎,同时支持iOS和Mac系统 作用 ? 1 2 3 4 5 6 7 8 9 <code>Quartz 2D能完成的工作 绘制图形 ...
- IE bug:ajax请求返回304解决方案
bug说明: 同一账户下的默认收货地址只有一个,默认收货地址可以修改,修改完成后,使用ajax重新加载收货地址部分. 默认收货地址状态标记:status = 1: 在IE浏览器做了修改后,重新加载的数 ...
- CentOS 7 GUI图形界面安装
在此之前先获取root权限,进行以下命令: 1. 在命令行下输入下面的命令来安装Gnome包: yum groupinstall "GNOME Desktop" "Gra ...
- css3兼容IE8的方案 各个ie的hack
虽然现在很多项目已经对低版本IE不要求了,但是还有部分公司对IE8还是很执着的,咱作为屌丝前端程序员不能和老板说前端潮流,不能说趋势,只能动脑子了,下面就分享一些css3兼容ie8的方案思路.主要是实 ...
- Python内置函数(34)——filter
英文文档: filter(function, iterable) Construct an iterator from those elements of iterable for which fun ...
- xftp上传文件失败,执行程序发现磁盘满了:No space left on device
参考链接 No space left on device 解决Linux系统磁盘空间满的办法http://www.cnblogs.com/aspirant/p/3604801.html如何解决linu ...