codeforces158D
Ice Sculptures
The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular n-gon. They are numbered in clockwise order with numbers from 1 to n.
The site of the University has already conducted a voting that estimated each sculpture's characteristic of ti — the degree of the sculpture's attractiveness. The values of ti can be positive, negative or zero.
When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that:
- the remaining sculptures form a regular polygon (the number of vertices should be between 3 and n),
- the sum of the ti values of the remaining sculptures is maximized.
Help the Vice Rector to analyze the criticism — find the maximum value of ti sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved.
Input
The first input line contains an integer n (3 ≤ n ≤ 20000) — the initial number of sculptures. The second line contains a sequence of integers t1, t2, ..., tn, ti — the degree of the i-th sculpture's attractiveness ( - 1000 ≤ ti ≤ 1000). The numbers on the line are separated by spaces.
Output
Print the required maximum sum of the sculptures' attractiveness.
Examples
8
1 2 -3 4 -5 5 2 3
14
6
1 -2 3 -4 5 -6
9
6
1 2 3 4 5 6
21
Note
In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.
sol:想了半天都不会,然后看题解,然后惊呼这TM能过??
for(i=;i*<=n;i++)
{
if(n%i==)
{
for(j=;j<=i;j++)
{
int Sum=;
for(k=j;k<=n;k+=i)
{
Sum+=a[k];
}
ans=max(ans,Sum);
}
}
}
这也太暴力了吧,我怎么算复杂度都是n2及以上啊,为什么能过啊qaq
Ps:不管了,弃了弃了(跪求更好的做法或证明一下复杂度)
4.3updata:这是调和级数的复杂度,似乎是n1.5。实锤不会算复杂度qaq
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,a[N];
int main()
{
int i,j,k,ans=-0x3f3f3f3f;
R(n);
for(i=;i<=n;i++) R(a[i]);
for(i=;i*<=n;i++)
{
if(n%i==)
{
for(j=;j<=i;j++)
{
int Sum=;
for(k=j;k<=n;k+=i)
{
Sum+=a[k];
}
ans=max(ans,Sum);
}
}
}
Wl(ans);
return ;
}
/*
input
8
1 2 -3 4 -5 5 2 3
output
14 input
6
1 -2 3 -4 5 -6
output
9 input
6
1 2 3 4 5 6
output
21 input
4
1 -10 1 -10
output
-18
*/
codeforces158D的更多相关文章
随机推荐
- linux内存源码分析 - 内存压缩(实现流程)
本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 概述 本文章最好结合linux内存管理源码分析 - 页框分配器与linux内存源码分析 -伙伴系统(初始化和申请 ...
- Java线程和多线程(十五)——线程的活性
当开发者在应用中使用了并发来提升性能的同时,开发者也需要注意线程之间有可能会相互阻塞.当整个应用执行的速度比预期要慢的时候,也就是应用没有按照预期的执行时间执行完毕.在本章中,我们来需要仔细分析可能会 ...
- Maven 多模块引用版本的问题 java.lang.NoSuchMethodError
环境:Junit测试用例 java.lang.NoSuchMethodError 很明显的错误,肯定是jar版本的问题 前提 Maven 打包并没有这个的问题,估计是做了优化处理 原测试代码 @Run ...
- Mysql字段名与保留字冲突导致的异常解决
一:引言 用hibernate建表时经常遇到的一个异常:Error executing DDL via JDBC Statement 方法: 查看报错sql语句.问题就在这里. 我是表名(字段名)与保 ...
- mariadb(第五章)视图、事物、索引、外键
视图 对于复杂的查询,在多个地方被使用,如果需求发生了改变,需要更改sql语句,则需要在多个地方进行修改,维护起来非常麻烦 假如因为某种需求,需要将user拆房表usera和表userb,该两张表的结 ...
- 六、input框中的数字(金额)只能输入正整数
<input type="text" placeholder="请输入整数" onkeyup="this.value=this.value.re ...
- PYTHON访问数据库
PYTHON DB API(规范)框架 可以一次编写同时访问MySql\ Oracle \SQLServer...不同的数据库服务器:统一接口程序的混乱. 1.连接访问:connection(高速路) ...
- poj2104 主席树裸题
空间大小:n*lgn 复杂度:建树n*lgn 查询lgn #include <cstdio> #include <iostream> #include <algorit ...
- c++入门之类继承初步
继承是面向对象的一种很重要的特性,先来复习基类的基本知识: 先上一段代码: # ifndef TABLE00_H # define TABLE00_H # include "string&q ...
- AndroidManifest.xml文件解析
一.关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(activiti ...