分金币 (UVA 11300)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33899
思路:推公式,发现可以转化为求给定n个数,求到所有点距离之和最小的点的问题
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#define RPE(i,n) for(int i=1;i<=(n);i++)
typedef long long LL;
const int maxn=1e6+;
LL a[maxn],c[maxn];
using namespace std;
int main()
{
ios::sync_with_stdio(false);
int n,ca=;
while(cin>>n)
{
LL sum=;
RPE(i,n)
{
cin>>a[i];
sum+=a[i];
}
LL m=sum/n;
c[]=;
RPE(i,n)
{
c[i]=c[i-]-(a[i]-m);
} sort(c+,c+n+); LL ans=; RPE(i,n) ans+=abs(c[i]-c[n/]); cout<<ans<<endl;
}
return ;
}
分金币 (UVA 11300)的更多相关文章
- 分金币 Uva 11300
题意 给定N个人成环状坐,每个人初始分配Ai的金币,金币总数可以被N整除,每个人可以给左右相邻的人一定数量的金币使得最终每个人的金币数量相同,求转移数量最小的方案所转移的总金币数量. N<=10 ...
- 【贪心+中位数】【UVa 11300】 分金币
(解方程建模+中位数求最短累积位移) 分金币(Spreading the Wealth, UVa 11300) 圆桌旁坐着n个人,每人有一定数量的金币,金币总数能被n整除.每个人可以给他左右相邻的人一 ...
- cogs 1430. [UVa 11300]分金币
1430. [UVa 11300]分金币 ★☆ 输入文件:Wealth.in 输出文件:Wealth.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] 圆桌旁坐着 ...
- UVA - 11300 Spreading the Wealth(数学题)
UVA - 11300 Spreading the Wealth [题目描述] 圆桌旁边坐着n个人,每个人有一定数量的金币,金币的总数能被n整除.每个人可以给他左右相邻的人一些金币,最终使得每个人的金 ...
- uva 11300 - Spreading the Wealth(数论)
题目链接:uva 11300 - Spreading the Wealth 题目大意:有n个人坐在圆桌旁,每个人有一定的金币,金币的总数可以被n整除,现在每个人可以给左右的人一些金币,使得每个人手上的 ...
- UVA.11300 Spreading the Wealth (思维题 中位数模型)
UVA.11300 Spreading the Wealth (思维题) 题意分析 现给出n个人,每个人手中有a[i]个数的金币,每个人能给其左右相邻的人金币,现在要求你安排传递金币的方案,使得每个人 ...
- 数学/思维 UVA 11300 Spreading the Wealth
题目传送门 /* 假设x1为1号给n号的金币数(逆时针),下面类似 a[1] - x1 + x2 = m(平均数) 得x2 = x1 + m - a[1] = x1 - c1; //规定c1 = a[ ...
- 分金币 bzoj 3293
分金币(1s 128M) coin [问题描述] 圆桌上坐着n个人,每人有一定数量的金币,金币总数能被n整除.每个人可以给他左右相邻的人一些金币,最终使得每个人的金币数目相等.你的任务是求出被转手的 ...
- UVa 11300 Spreading the Wealth(有钱同使)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: "Times New ...
- 【BZOJ-3293&1465&1045】分金币&糖果传递×2 中位数 + 乱搞
3293: [Cqoi2011]分金币 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 854 Solved: 476[Submit][Status] ...
随机推荐
- FreeMarker:模板开发指南
ylbtech-FreeMarker:模板开发指南 1.返回顶部 1. Section Contents 入门 模板 + 数据模型 = 输出 数据模型一览 模板一览 数值,类型 基本内容 类型 模板 ...
- 10.11 NOIP模拟题(1)
/* 离散化 差分 */ #include<bits/stdc++.h> #define N 4000007 using namespace std; int n,ans; int tmp ...
- 【杂文】虚拟键码表(供函数GetAsyncKeyState()使用)
[杂文]虚拟键码表(供函数GetAsyncKeyState()使用) 什么?你说你不知道 \(GetAsyncKeyState()\) ?\(→\)戳我\(←\) (惊奇的发现 \(0\) ~ \(9 ...
- 最大加权矩形 luogu1719
题目链接:https://www.luogu.org/problemnew/show/P1719 这道题挺好做的 又是一道练前缀和的题 #include <bits/stdc++.h> # ...
- PWBI--Excel 数据源
博客园地址: http://blog.sina.com.cn/s/blog_68c4467d0102w5cc.html http://www.cnblogs.com/asxinyu/p/Power_B ...
- ACM_下一个排列
The Next Permutation Time Limit: 2000/1000ms (Java/Others) Problem Description: For this problem, yo ...
- HBuilder发行原装安装包操作记录
1.在左侧"项目管理器"中选择项目: 2.点击菜单栏中的"发行-->发行为原生安装包": 3.在弹出的App云端打包中填写相关信息: IOS开发者证书配置 ...
- [ ZJOI 2010 ] 网络扩容
\(\\\) Description 给定一张有向图,每条边都有一个容量 \(C\) 和一个扩容费用 \(W\). 这里扩容费用是指将容量扩大 \(1\) 所需的费用.求: 在不扩容的情况下, \(1 ...
- CF817B Makes And The Product
思路: 模拟,数学. 实现: #include <iostream> #include <cstdio> #include <algorithm> using na ...
- switch-case用法
1.switch-case 一般的用它来做值匹配的. //匹配 就是全等. /* 语法: switch(表达式){ case 值1: 表达式的值和 值1匹配上了,需要执行的代码; break; cas ...