codeforces 863B
来源:互联网 发布:excel表格重复数据合并 编辑:程序博客网 时间:2024/06/02 04:23
Kayaking
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.
Example
Input
2
1 2 3 4
Output
1
Input
4
1 3 4 6 3 4 100 200
Output
5
题意:2*n个人有n-1个双人皮艇,2个单人的,单人的不稳定性是0,双人的不稳定性是两个人体重的差值,如果差值太大就会坠毁。求解最小的不稳定值。
思路:把所有的情况都算一遍找到最小的值(看到这种方法我也很无奈。。。我也没想到还有这种操作)
#include<stdio.h>#include<algorithm>#include<iostream>#include<string.h>using namespace std;long long a[1000];long long b[1000];int main(){ int n; while(~scanf("%d",&n)) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(int i=1; i<=2*n; i++) { scanf("%lld",&a[i]); } int N=2*n; long long anss=1000000; sort(a+1,a+N+1); for(int i=1; i<2*n; i++) { for(int j=i+1; j<=2*n; j++) { long long ans=0; int x=0; for(int k=1; k<=2*n; k++) { if(k!=i&&k!=j) { b[x++]=a[k]; if(x%2==0) ans+=(abs(b[x-1]-b[x-2])); } } //cout<<ans<<endl; anss=min(anss,ans); } } printf("%lld\n",anss); }}
- codeforces 863B Kayaking
- codeforces 863B
- codeforces 863B
- codeforces 863B 之 Kayaking
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- codeforces B. Coins
- codeforces----193B Xor
- codeforces----208B Solitaire
- Codeforces 1B - Spreadsheet
- 纯用sdk添加linux镜像到flash启动linux
- 嵌入式学习笔记_Linux(三)——Linux进程控制
- bat批处理实现数据库备份、压缩、删除
- iOS 10+ prefs:root=xxxx 从第三方应用跳转到设置已不可用
- logistic回归算法详细分析与Python代码实现注释
- codeforces 863B
- Oc 正则表达式~详解 02 (方法名总结)
- JVM原理之内存分配参数
- SDIO接口WiFi驱动浅析
- 实验二线性表的综合实验5
- LiteOS之任务管理
- bzoj1426 [收集邮票] 期望概率DP进阶
- 在 SSM 框架整合 Shiro 的相关案例
- poj2229动态规划