leetcode 561
来源:互联网 发布:贪心算法会场安排问题 编辑:程序博客网 时间:2024/06/10 14:52
题目:Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possible.
方法:将数组从小到大排序,然后选择索引为偶数的数相加。
翻译:给2n个数的数组,把它们分为n组,取每组中最小的数使其相加和最大。
思想:贪心算法。理解:简单点说一组已经从小到排好序的数组,从最大值开始,最大值肯定是取不到的,那么,取次大的数,也就是倒数第二个数,以此类推,顺其自然,都是取的索引位置为偶数的数。
Java函数:Arrays.sort();可以自动对数组排序。
0 0
- leetcode 561
- LeetCode 561 : ArrayPartition I
- leetcode 561---- ArrayPartition
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- leetcode
- [leetcode]
- LeetCode
- 腾讯云发布无服务器云函数,较云主机成本低约70%
- Ubuntu 16.04 安装Jenkins持续集成
- ionic2 中隐藏子页面tabs选项卡的三种方法
- 记录1年免费亚马逊AWS云服务器申请方法过程及使用技巧
- R语言常见的问题?
- leetcode 561
- 中科爱讯推出LoRa系列产品:网关传输距离达20公里
- 应用开发
- java生成压缩文件
- 内部类初始化
- 安卓设计模式(一)面向对象六大设计原则
- java程序猿的成长记录之(三)分享一种防猜的加密算法
- Centos7安装nginx
- 多渠道打包,调试程序(debug app)