<pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

          <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

          <p id="bbfd9"></p>

          <p id="bbfd9"><cite id="bbfd9"></cite></p>

            <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

            <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
            <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>

            我在屋里練射箭作文1200字

            時間:2025-12-09 14:34:54 1200字 我要投稿

            我在屋里練射箭作文1200字

              有兩個序列a,b,大小都為n,序列元素的值任意整形數,無序;

            我在屋里練射箭作文1200字

              要求:通過交換a,b中的元素,使[序列a元素的和]與[序列b元素的和]之間的差最小。

              1. 將兩序列合并為一個序列,并排序,為序列Source

              2. 拿出最大元素Big,次大的元素Small

              3. 在余下的序列S[:-2]進行平分,得到序列max,min

              4. 將Small加到max序列,將Big加大min序列,重新計算新序列和,和大的為max,小的為min。

              Python代碼

              def mean( sorted_list ):

              if not sorted_list:

              return (([],[]))

              big = sorted_list[-1]

              small = sorted_list[-2]

              big_list, small_list = mean(sorted_list[:-2])

              big_list.append(small)

              small_list.append(big)

              big_list_sum = sum(big_list)

              small_list_sum = sum(small_list)

              if big_list_sum > small_list_sum:

              return ( (big_list, small_list))

              else:

              return (( small_list, big_list))

              tests = [ [1,2,3,4,5,6,700,800],

              [10001,10000,100,90,50,1],

              range(1, 11),

              [12312, 12311, 232, 210, 30, 29, 3, 2, 1, 1]

              ]

              for l in tests:

              l.sort()

              print

              print “Source List:\t”, l

              l1,l2 = mean(l)

              print “Result List:\t”, l1, l2

              print “Distance:\t”, abs(sum(l1)-sum(l2))

              print ‘-*’*40

              輸出結果

              Python代碼

              Source List: [1, 2, 3, 4, 5, 6, 700, 800]

              Result List: [1, 4, 5, 800] [2, 3, 6, 700]

              Distance: 99

              -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

              Source List: [1, 50, 90, 100, 10000, 10001]

              Result List: [50, 90, 10000] [1, 100, 10001]

              Distance: 38

              -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

              Source List: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

              Result List: [2, 3, 6, 7, 10] [1, 4, 5, 8, 9]

              Distance: 1

              -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

              Source List: [1, 1, 2, 3, 29, 30, 210, 232, 12311, 12312]

              Result List: [1, 3, 29, 232, 12311] [1, 2, 30, 210, 12312]

              Distance: 21

            【我在屋里練射箭作文1200字】相關文章:

            射箭比賽500字作文04-16

            山屋里的微感動作文02-20

            書屋里的溫暖作文(通用25篇)01-08

            第一次體驗射箭作文03-21

            攀巖與射箭的作文800字(通用37篇)02-26

            第一次射箭作文(精選25篇)04-16

            我的拿手好戲練書法作文650字(精選35篇)03-07

            我為練鋼琴而煩惱550字作文(通用20篇)10-15

            游泳訓紅練的感受作文07-26

            練足球作文(通用15篇)11-25

            • 相關推薦

                    <pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

                    <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

                    <p id="bbfd9"></p>

                    <p id="bbfd9"><cite id="bbfd9"></cite></p>

                      <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

                      <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
                      <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>
                      飘沙影院