1. 程式人生 > >現有n堆球,其中n是偶數,第i堆中有 ai 個球。現需要將其中 n / 2 堆中的球數全變成完 全平方數,另外的 n / 2 全不為完全平方數。

現有n堆球,其中n是偶數,第i堆中有 ai 個球。現需要將其中 n / 2 堆中的球數全變成完 全平方數,另外的 n / 2 全不為完全平方數。

bcd dba amp com http abc 一行 增加 完全平方數

【問題描述】
現有n堆球,其中n是偶數,第i堆中有 ai 個球。現需要將其中 n / 2 堆中的球數全變成完
全平方數,另外的 n / 2 全不為完全平方數。你每一次操作可以選擇任意一堆增加或拿走(前
提不為 0)一個球。試問最少需要多少次操作可以滿足要求。
【輸入】
第一行輸入n (2 ≤n ≤ 200 000)為球的 堆數。
第二行輸入𝑛個的非負整數 a1,?a2,?...,?an (0≤?ai ≤?109) 每堆的球數。
【輸出】
輸出最少的操作步數。
【輸入樣例】
4
12 14 30 4
【輸出樣例】
2
【輸入樣例】
6
0 0 0 0 0 0
【輸出樣例】
6

http://shijue.me/community/photo-details/c4ef27b44f214e828dad0ded9031e906_d
http://shijue.me/community/photo-details/2eb9ac40ec26489bbaa3aab75e70c42b_d
http://shijue.me/community/photo-details/cf8ab96c8963440996bea744cc5f569b_d
http://shijue.me/community/photo-details/3576e5a5dd354384a68075115bac1f69_d
http://shijue.me/community/photo-details/b35b71b77206445d83b9201dd46afc32_d
http://shijue.me/community/photo-details/de35f29c14624dafb18d6ae224739d99_d
http://shijue.me/community/photo-details/4163b512b5f245e9b6844976d8c6f03d_d
http://shijue.me/community/photo-details/931491144aaa4ff0852f4daff79a0430_d
http://shijue.me/community/photo-details/598d9b1203414433b25a31063d66fd29_d
http://shijue.me/community/photo-details/20febbc8e41a46808ff8b8545aefdbed_d
http://shijue.me/community/photo-details/c3c9d26c8952443ea0488b57264dbbad_d
http://shijue.me/community/photo-details/2756cc15c93c4376bd3da95a3f27e628_d
http://shijue.me/community/photo-details/a2191c1e068f4f23a1018cc11b82fabe_d
http://shijue.me/community/photo-details/82462730dba64eb0952783bef227806e_d
http://shijue.me/community/photo-details/30f5f1b8de6a4998958332fbdeac2969_d
http://shijue.me/community/photo-details/d92ce84fa44b40a4a556d09bd1f6aa27_d
http://shijue.me/community/photo-details/f2dc5e91fee94b2c9de3cd168016e437_d
http://shijue.me/community/photo-details/601a022572404feb9a13d0ac9d3db96a_d
http://shijue.me/community/photo-details/387324aa49364a02b85e2dfd8ec240af_d
http://shijue.me/community/photo-details/dad4e68ee4664f528b6a0b9630a54a31_d
http://shijue.me/community/photo-details/5d762e1b87544fd3a2afbabcadbbe93d_d
http://shijue.me/community/photo-details/9122cf5d76c74e1fb31f2370410a4ae5_d
http://shijue.me/community/photo-details/af0fb1cb0f8a45b299afb3e04481b404_d
http://shijue.me/community/photo-details/83d8d8f57b1a455791febbe2df4427f0_d
http://shijue.me/community/photo-details/bec18d2ce97645fd9abcda1bf1f4ad00_d
http://shijue.me/community/photo-details/628d8a296fc94a55a293de4f7b077f3a_d
http://shijue.me/community/photo-details/4b1632aca49a45f4a4fe36d9748ce5bf_d
http://shijue.me/community/photo-details/305544f9f6c74c1a8e1078ce376e8070_d
http://shijue.me/community/photo-details/5a420d6e19a24cc683b08ac69ab17b8e_d
http://shijue.me/community/photo-details/c50c94fc30f443fd8f7742e97c25107e_d
http://shijue.me/community/photo-details/460d02a991674a65905f635d7bb58e58_d
http://shijue.me/community/photo-details/46fd626e3043415f9b2d751e14491610_d
http://shijue.me/community/photo-details/8f6b9dd484e346ffa728338b290bb1a8_d
http://shijue.me/community/photo-details/e4af92546bdf4054b3d1bcaa3b6231e4_d
http://shijue.me/community/photo-details/2911f9da46674a59a6be22acd56e636d_d
http://shijue.me/community/photo-details/82929ac7b418417fb505f111bbe02cdd_d
http://shijue.me/community/photo-details/e07f8290039847e9ba873524b7b6327d_d

現有n堆球,其中n是偶數,第i堆中有 ai 個球。現需要將其中 n / 2 堆中的球數全變成完 全平方數,另外的 n / 2 全不為完全平方數。