现有n堆球,其中n是偶数,第i堆中有 ai 个球。现需要将其中 n / 2 堆中的球数全变成完 全平方数,另外的 n / 2 全不为完全平方数。

Posted dsfsf

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了现有n堆球,其中n是偶数,第i堆中有 ai 个球。现需要将其中 n / 2 堆中的球数全变成完 全平方数,另外的 n / 2 全不为完全平方数。相关的知识,希望对你有一定的参考价值。

【问题描述】
现有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 全不为完全平方数。的主要内容,如果未能解决你的问题,请参考以下文章

2021-08-24:合并石头的最低成本。有 N 堆石头排成一排,第 i 堆中有 stones[i] 块石头。每次移动(move)需要将连续的 K 堆石头合并为一堆,而这个移动的成本为这 K 堆石头的

bzoj 4874: 筐子放球

合并金币

BZOJ4555求和(cdq分治+NTT)

2023-05-05:给定一个无向连通的树 树中有 n 个标记为 0...n-1 的节点以及 n-1 条边 。 给定整数 n 和数组 edges , edges[i] = [ai, bi]表示树中的

[HEOI2016]求和 sum