2A - Stone
任意一堆移动过后的石子都是整数x的倍数,
那么石子总数显然也应该是x的倍数,
换句话说,x必为石子数总和的一个质因子.
题目要求移动次数尽量小,那么x也应该尽量小.
所以选择石子数总和的最小质因子.
对每堆石子数进行取模运算即可知道每堆石子需要移走或增加多少石子.
然后就可以开始模拟了.
把取模后的石子数进行从大到小的排序并求出取模后的石子总数,
然后求出可以组成x的个数.
用大石子堆到小石子堆去减这些x,在累加起来,即得到最少移动次数.
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll; ll arr[];
// 得到第一个质因子
ll getFac(ll x)
{
for (ll i = ; i <= x; i++)
if (x % i == )
return i;
return -;
} bool cmp(ll a, ll b)
{
return a >= b;
} int main()
{
ios::sync_with_stdio(false);
cin.tie(); int n;
cin >> n;
ll sum = ;
for (int i = ; i < n; i++) {
cin >> arr[i];
sum += arr[i];
} // 最小质因子的余数系最小
ll num = getFac(sum);
sum = ;
for (int i = ; i < n; i++) {
arr[i] = arr[i] % num;
sum += arr[i];
} // 模拟
sort(arr, arr + n, cmp);
ll k = sum / num;
ll ans = ;
for (int i = ; i < k; i++) {
ans += num - arr[i];
}
cout << ans << endl;
return ;
}
2A - Stone的更多相关文章
- 红米2A高配刷机记录
2014816 机型:红米2A高配版 设备型号:2014816 CPU:高通 线刷:fastboot平台 http://192.168.7.118/MesReports/Reports/Cutting ...
- POJ1740A New Stone Game[组合游戏]
A New Stone Game Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5769 Accepted: 3158 ...
- timus 1180. Stone Game 解题报告
1.题目: 1180. Stone Game Time limit: 1.0 secondMemory limit: 64 MB Two Nikifors play a funny game. The ...
- mac上执行sed的编辑 -i命令报错sed: 1: "test.txt": undefined label ‘est.txt’或sed: 1: "2a\test\": extra characters after \ at the end of a command
问题一 sed编辑命令:[sed -i 's/a/b/g' test.txt] 报错:sed: 1: "test.txt": undefined label 'est.txt' ...
- HDU 4048 Zhuge Liang's Stone Sentinel Maze
Zhuge Liang's Stone Sentinel Maze Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/327 ...
- POJ 1740 A New Stone Game
A New Stone Game Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5453 Accepted: 2989 ...
- Light OJ 1296 - Again Stone Game (博弈sg函数递推)
F - Again Stone Game Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- poj 1115 Lifting the Stone 计算多边形的中心
Lifting the Stone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- 【POJ】A New Stone Game(博弈论)
http://poj.org/problem?id=1740 题目大意就是,对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该堆剩余石子的一部分分 ...
随机推荐
- oracle误删数据的解决方法
之前不小心误删了一条数据,索性我还记得id,通过select * from 表名 as of timestamp to_timestamp('2017-6-23 9:10:00','yyyy-mm-d ...
- 在Win7 64位电脑上安装Sql Server 2008 R2 Express
安装环境说明: 操作系统:Win7 64位 英文版 安装步骤: 1.准备安装文件 下载网址:https://www.microsoft.com/zh-CN/download/details.aspx? ...
- Rails 和 Django 的深度技术对比
我想以一个免责声明来开始下面的内容.我使用 Django开发网站已经有三年了,众所周知,我喜欢Django.我已经写了一个开源的应用程序( app),并且我已经将补丁发送到了Django.然而,我以尽 ...
- CentOS双网卡双IP设置
CentOS双网卡双IP设置 系统环境:CentOS Linux 网络环境: 两个IP地址,192.168.0.10和10.10.30.2,掩码是255.255.255.0,这两个子网的网关地址分别是 ...
- Vivado生成edf文件
https://china.xilinx.com/support/answers/54074.html 综合完成后会跳出个框框,选择open synthesis write_edif module. ...
- jQuery form 插件
http://jquery.malsup.com/form/#getting-started 举例: $(document).ready(function() { $('#ff').ajaxForm( ...
- portableDFS-可便携的分布式文件系统
PPT下载(因附件大小有限制,删除了PPT中的隐藏页,如需完整版本,请转到it168文库下载):portableDFS-可便携的分布式文件系统.ppt 完整版本请上这里下载:http://wenku. ...
- 编写高质量代码改善C#程序的157个建议——建议21:选择正确的集合
建议21:选择正确的集合 要选择正确的集合,首先要了解一些数据结构的知识.所谓数据结构,就是相互之间存在一种或多种特定关系的数据元素的集合. 集合的分类参考下图: 由于非泛型集合存在效率低及非类型安全 ...
- android获取USB设备的名称
1.注释内 .是三星设备可能不支持,需要更换的代码. 2.mUsbManager.是getSystemService(Context.USB_SERVICE)获的. 3. 从stackoverflow ...
- Sharepoint2013搜索学习笔记之设置外网内容源(四)
第一步,进入管理中心,点击管理应用程序,点击search service 应用程序进入到搜索管理配置页面,选择内容源 第二步,点击新建内容源,给内容源命名,在爬网内容类型中选网站,在爬网设置中选中仅对 ...