这道题和负载平衡问题是同一道题, 如果 $n <= 100$ 的话是可以用最小费用流来求解的。
但是题中 $n$ 最大可达到 $10^6$, 这就需要我们进行一些性质分析与推导。
首先, 我们设每个·人手里最终金币数为 $C$
设 $X_{i}$ 为第 $i$个人给第 $i+1$ 个人的金币数目, 这个数目可以为负(第$i + 1$ 个人向左给了第$i$ 个人$|X_{i}|$个。
则我们不难发现:
1. $A_{2}+X_{1}-X_{2}=C$
2. $A_{3}+X_{2}-X_{3}=C$
3. $A_{4}+X_{3}-X_{4}=C$
4. ...
5. $A_{i}+X_{i-1}-X_{i}=C$
而这道题要求的其实就是$min|X_{1}| + |X_{2}| + |X_{3}| + |X_{4}| +... |X_{n}|$
那么,我们可将上面的等式进行变形,得:
1. $X_{1} = X_{1}$
2. $X_{2} =A_{2}-C+X_{1}$
3. $X_{3} =A_{2} + A_{3}-2*C+X_{1}$
4. $X_{4} =A_{2} + A_{3} +A_{4}-3*C+X_{1}$
5. $X_{5} =A_{2}+A_{3}+A_{4}+A_{5}-4*C+X_{1}$
此时,相信聪明的读者们不难发现规律:
$X_{i} = \sum\limits_{k=2}^i-(i-1)*C+X_{1}$ 即 $X_{i} = \sum\limits_{k=2}^i-(i-1)*C-(-X_{1})$
我们可以把$X_{1}$抽象成数轴上的一个点, 我们设$g_{i}= \sum\limits_{k=2}^i-(i-1)*C$,那么我们希望 $X_{1}$ 到所有 $g_{i}$ 的距离和最短,这个 $X_{i}$ 一定是 $g_{i}$中的中位数,于是我们将所有的 $g_{i}$ 排序,取中位数作为 $X_{1}$ 即可,我们也就能顺便推出所有的 $X_{i}$ ,最后加和即可,总时间复杂度为 $O(nlogn)$

uva 11300 Spreading the Wealth_数学推倒 + 思维的更多相关文章

  1. 数学/思维 UVA 11300 Spreading the Wealth

    题目传送门 /* 假设x1为1号给n号的金币数(逆时针),下面类似 a[1] - x1 + x2 = m(平均数) 得x2 = x1 + m - a[1] = x1 - c1; //规定c1 = a[ ...

  2. UVA.11300 Spreading the Wealth (思维题 中位数模型)

    UVA.11300 Spreading the Wealth (思维题) 题意分析 现给出n个人,每个人手中有a[i]个数的金币,每个人能给其左右相邻的人金币,现在要求你安排传递金币的方案,使得每个人 ...

  3. UVa 11300 Spreading the Wealth(有钱同使)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: "Times New ...

  4. uva 11300 - Spreading the Wealth(数论)

    题目链接:uva 11300 - Spreading the Wealth 题目大意:有n个人坐在圆桌旁,每个人有一定的金币,金币的总数可以被n整除,现在每个人可以给左右的人一些金币,使得每个人手上的 ...

  5. UVA - 11300 Spreading the Wealth(数学题)

    UVA - 11300 Spreading the Wealth [题目描述] 圆桌旁边坐着n个人,每个人有一定数量的金币,金币的总数能被n整除.每个人可以给他左右相邻的人一些金币,最终使得每个人的金 ...

  6. UVA 11300 Spreading the Wealth (数学推导 中位数)

    Spreading the Wealth Problem A Communist regime is trying to redistribute wealth in a village. They ...

  7. 【思维】UVA 11300 Spreading the Wealth

    题目大意 vjudge链接 有n个人围圆桌而坐,每个人有Ai个金币,每个人可以给左右相邻的人一些金币. 若使得最终所有人金币数相等,求最小金币转移数. 数据范围 n<1000001 样例输入 3 ...

  8. Uva 11300 Spreading the Wealth(递推,中位数)

    Spreading the Wealth Problem A Communist regime is trying to redistribute wealth in a village. They ...

  9. Math - Uva 11300 Spreading the Wealth

    Spreading the Wealth Problem's Link ---------------------------------------------------------------- ...

随机推荐

  1. 强大的JQuery链式操作风格

    实例代码 <style type="text/css"> #menu {width: 300px;} .has_children {background:#555;co ...

  2. Bash中文速查表

    最好用的中文速查表(Cheatsheet) 来源:https://github.com/skywind3000/awesome-cheatsheets 感谢网友们的贡献! ############## ...

  3. web service服务是查询QQ用户是否在线

    使用php5开发客户端: <?php try { //$client = new SoapClient("HelloService.wsdl",array('encoding ...

  4. [HEOI2013]Eden 的新背包问题

    数据极水,不加优化的多重背包都能过...早知道考试的时候不加奇奇怪怪的卡常优化,卡了45分... 就是从前往后做一个多重背包,从后往前再做一个,问的时候就暴力求一下跳过这个的最佳方案... #incl ...

  5. Spring Boot浅谈(是什么/能干什么/优点和不足)

    1. Spring Boot是什么,解决哪些问题 1) Spring Boot使编码变简单 2) Spring Boot使配置变简单 3) Spring Boot使部署变简单 4) Spring Bo ...

  6. 【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) A】Palindrome Dance

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] i从1..n/2循环一波. 保证a[i]和a[n-i+1]就好. 如果都是2的话填上min(a,b)*2就好 其他情况跟随非2的. ...

  7. net--技术栈(大图)

  8. 不可靠信号SIGCHLD丢失的问题

    如果采用 void sig_chld(int signo) {        pid_t pid;        int stat;                while((pid = waitp ...

  9. Jasperreport+ireport 实践操作及web应用

    Jasperreport+ireport 实践操作及web应用   学习完jasperreports+ireport,给我感觉深刻,不仅掌握了报表开发技术,还掌握了怎样在web中生成pdf,xls,r ...

  10. 【1】按照Django官网,编写一个web app 创建project/配置数据库

    1. Creating a project From the command line, cd into a directory where you'd like to store your code ...