Codeforces Round #601 (Div. 2) E1 Send Boxes to Alice (Easy Version)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+;
int a[N];
int n;
bool prime(int x) {//判断是否为质数
for(int i = ; i*i <= x; i++) {
if(x%i == ) return false;
}
return true;
}
ll solve(int x) {
vector<int>b;
ll ans = ;
for(int i = ; i <= n; i++) {
if(a[i] == && b.size() < x) b.push_back(i);//存放位置
if(b.size() == x) {
for(int j = ; j < b.size(); j++) {
ans += (ll)abs(b[j]-b[x/]);
}
b.clear();
}
}
return ans;
}
int main() {
int sum = ;
scanf("%d",&n);
for(int i = ; i <= n; i++) {
scanf("%d",a+i);
sum += a[i];
}
if(sum == ) {
printf("-1\n");
return ;
}
ll ans = 0x3f3f3f3f3f;
for(int i = ; i <= sum; i++) {
if(sum%i==&&prime(i)) {//此处用质因子优化,不加优化也行。
ans = min(ans,solve(i));
}
}
printf("%lld\n",ans);
return ;
}
Codeforces Round #601 (Div. 2) E1 Send Boxes to Alice (Easy Version)的更多相关文章
- Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version)
Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version) N个盒子,每个盒子有a[i]块巧克力,每次操作可以将盒子中的 ...
- E1.Send Boxes to Alice(Easy Version)//中位数
发送盒子给Alice(简单版本) 题意:准备n个盒子放巧克力,从1到n编号,初始的时候,第i个盒子有ai个巧克力. Bob是一个聪明的家伙,他不会送n个空盒子给Alice,换句话说,每个盒子里面都有巧 ...
- E1. Send Boxes to Alice (Easy Version)
题解: 保存每个1的位置.然后记录1的总个数cnt,如果存在一个k使得这个k是每个集合的倍数,那么为了使操作次数最小,这个k应该是cnt的质因子.(因为都是每个集合的数目1,使每个集合的数目变为2需要 ...
- Codeforces Round #601 (Div. 2)
传送门 A. Changing Volume 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/19 22:37:33 */ #include ...
- 【cf比赛记录】Codeforces Round #601 (Div. 2)
Codeforces Round #601 (Div. 2) ---- 比赛传送门 周二晚因为身体不适鸽了,补题补题 A // http://codeforces.com/contest/1255/p ...
- Codeforces Round #496 (Div. 3 ) E1. Median on Segments (Permutations Edition)(中位数计数)
E1. Median on Segments (Permutations Edition) time limit per test 3 seconds memory limit per test 25 ...
- Codeforces Round #278 (Div. 2) B. Candy Boxes [brute force+constructive algorithms]
哎,最近弱爆了,,,不过这题还是不错滴~~ 要考虑完整各种情况 8795058 2014-11-22 06:52:58 njczy2010 B - Ca ...
- Codeforces Round #601 (Div. 2) D Feeding Chicken
//为了连贯,采取一条路形式,从第一行开始 也就是s型 #include <bits/stdc++.h> using namespace std; ; char str[MAXN][MAX ...
- Codeforces Round #601 (Div. 2) C League of Leesins
把每一次输入的一组数字存下来,然后把每个数字出现的组数存下来 然后找只出现过一次的数字a,那么这个数字a不是开头就是结尾,默认为开头(是哪个都无所谓),然后去找和它出现在同一组的两个数字b和c,而b和 ...
随机推荐
- Bash脚本编程学习笔记07:循环结构体
本篇中涉及到算术运算,使用了$[]这种我未在官方手册中见到的用法,但是确实可用的,在此前的博文<Bash脚本编程学习笔记03:算术运算>中我有说明不要使用,不过自己忘记了.大家还是尽量使用 ...
- 搭建wordpress博客
环境说明 操作系统: CentOS 7.2 64位 1. 准备LAMP环境 LNMP 是 Linux.Nginx.MySQL 和 PHP 的缩写,是 WordPress 博客系统依赖的基础运行环境.我 ...
- 前端开发神器 VSCode 使用总结
VSCode 是微软出品的,基于 Electron 和 TypeScript 的,集成了 git 版本管理和命令行终端,而且开源稳定,插件丰富,再搭配一款 Chrome 浏览器,可以说是前端开发神器了 ...
- mysql-主从备份问题小结
一:防火墙 常用命令 firewall-cmd --state 或 systemctl status firewalld # 查看状态 systemctl start firewalld# 启动 sy ...
- Spring的BeanFactory和FactoryBean
官方定义 BeanFactory:Spring Bean容器的根接口 FactoryBean:各个对象的工厂接口,如果bean实现了这个接口,它将被用作对象的工厂,而不是直接作为bean实例. 源码解 ...
- 生成随机数(C++)
// generate random number #include <iostream> #include <iomanip> #include <cstdlib> ...
- Linux教程-修炼
在2020这个特殊的时期,在家就是为国家做贡献!一切都会好起来的,加油中国!! Linux 第1章 Linux 简介 1.1 为什么要学习Linux 1.2 Linux是什么 1.3 Linux 与 ...
- Java各种类
1.Object类 equals方法 2.Date类 构造方法 成员方法 DateFormat类 Calendar类 3.System类 StringBuilder原理 构造方法 toString方法 ...
- 剑指offer-面试题13-机器人的运动范围-递归法
/* 题目: 地上有一个m行n列的方格.一个机器人从坐标(0,0)的格子开始运动, 每次可向上.下.左.右移动一格,但不能进入行坐标和列坐标之和大于k的格子. 如,当k=18时,机器人能进入(35,3 ...
- 微信小程序直播资料整理
可以通过此脑图大概了解小程序直播内容:https://developers.weixin.qq.com/community/develop/article/doc/0002a62b3749f088fa ...