贪心 C - 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 w i, 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 w 1, w 2, …, w 2n, where w i is weight of person i (1 ≤ w i ≤ 1000).

Output
Print minimum possible total instability.

Examples
Input
2
1 2 3 4
Output
1
Input
4
1 3 4 6 3 4 100 200
Output
5

#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;
    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 max = 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]));
                    }
                }
                max = min(max, ans);
            }
        }
        printf("%lld\n", max);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
UCF101是一个动作识别数据集,包含101个不同的动作类别。每个类别有不同数量的样本,具体数目如下: 1. ApplyEyeMakeup: 145 2. ApplyLipstick: 114 3. Archery: 145 4. BabyCrawling: 132 5. BalanceBeam: 134 6. BandMarching: 167 7. BaseballPitch: 150 8. Basketball: 134 9. BasketballDunk: 137 10. BenchPress: 148 11. Biking: 150 12. Billiards: 145 13. BlowDryHair: 123 14. BlowingCandles: 100 15. BodyWeightSquats: 175 16. Bowling: 146 17. BoxJump: 131 18. BoxingPunchingBag: 147 19. BoxingSpeedBag: 148 20. BreastStroke: 148 21. BrushingTeeth: 146 22. CleanAndJerk: 151 23. CliffDiving: 141 24. CricketBowling: 145 25. CricketShot: 150 26. CuttingInKitchen: 150 27. Diving: 147 28. Drumming: 166 29. Fencing: 145 30. FieldHockeyPenalty: 156 31. FloorGymnastics: 173 32. FrisbeeCatch: 143 33. FrontCrawl: 156 34. GolfSwing: 166 35. Haircut: 139 36. HammerThrow: 139 37. HandstandPushups: 137 38. HandstandWalking: 166 39. HeadMassage: 144 40. HighJump: 145 41. HorseRace: 155 42. HorseRiding: 150 43. HulaHoop: 140 44. IceDancing: 147 45. JavelinThrow: 148 46. JugglingBalls: 166 47. JumpingJack: 151 48. JumpRope: 154 49. Kayaking: 116 50. Knitting: 100 51. LongJump: 140 52. Lunges: 146 53. MilitaryParade: 138 54. Mixing: 147 55. MoppingFloor: 151 56. Nunchucks: 118 57. ParallelBars: 149 58. PizzaTossing: 100 59. PlayingCello: 150 60. PlayingDaf: 100 61. PlayingDhol: 100 62. PlayingFlute: 149 63. PlayingGuitar: 147 64. PlayingPiano: 150 65. PlayingSitar: 100 66. PlayingTabla: 100 67. PlayingViolin: 148 68. PoleVault: 145 69. PommelHorse: 145 70. PullUps: 150 71. Punch: 150 72. PushUps: 150 73. Rafting: 100 74. RockClimbingIndoor: 155 75. RopeClimbing: 141 76. Rowing: 150 77. SalsaSpin: 150 78. ShavingBeard: 144 79. Shotput: 146 80. SkateBoarding: 144 81. Skiing: 146 82. Skijet: 100 83. SkyDiving: 144 84. SoccerJuggling: 133 85. SoccerPenalty: 152 86. StillRings: 145 87. SumoWrestling: 145 88. Surfing: 147 89. Swing: 150 90. TableTennisShot: 145 91. TaiChi: 106 92. TennisSwing: 145 93. ThrowDiscus: 145 94. TrampolineJumping: 145 95. Typing: 144 96. UnevenBars: 144 97. VolleyballSpiking: 149 98. WalkingWithDog: 152 99. WallPushups: 145 100. WeightedSquat: 147 101. Windsurfing: 143

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值