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的更多相关文章
随机推荐
- C#使用Json.Net遍历Json
StringBuilder builder=new StringBuilder(); builder.AppendLine("{"); builder.AppendLine(&qu ...
- Spring+SpringMVC+Mybatis框架整合流程
一:基本步骤 新建Maven项目,导入相关依赖.(推荐) ————–Mybatis配置 —————- 新建entity包,并根据数据库(表)新建相关实体类. 新建dao包,并根据业务创建必要的mapp ...
- 使用Python的http.server实现一个简易的Web Api对外提供HanLP拼音转换服务
由于采集省市区镇数据需要对地名进行拼音转换,由于第三方高准确度接口对IP进行了限制,处理大量数据变得异常缓慢. 使用了一个折中的办法,省市区 3级(3千+)用高准确度接口(几乎没有拼错的地名),镇级( ...
- Python股票分析系列——数据整合.p7
欢迎来到Python for Finance教程系列的第7部分. 在之前的教程中,我们为整个标准普尔500强公司抓取了雅虎财经数据. 在本教程中,我们将把这些数据组合到一个DataFrame中. 到此 ...
- C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - 严格的用户账户审核功能
整个集团有几万个用户,一个个用户添加是不现实的,只有每个公司的系统管理员添加.或者用户申请帐户,然后有相应的管理员审核,才会更准确一些. 每个公司.分公司.部门的账户情况只有所在公司的管理员是最清楚的 ...
- Python全栈开发之路 【第十五篇】:jQuery的介绍和选择器
本节内容 什么是jQuery? write less,do more. jQuery是一个快速,小巧,功能丰富的JavaScript库. 它通过易于使用的API在大量浏览器中运行,使得HTML文档遍历 ...
- OO博客作业1:第1-3周作业总结
(1)基于度量来分析自己的程序结构 注:UML图中每个划分了的圆角矩形代表一个类或接口,箭头可代表创建.访问数据等行为.类的图形内部分为3个部分,从上到下依次是类的名称.类包含的实例变量(属性).类实 ...
- Codeforces Round #486 (Div. 3)-C. Equal Sums
C. Equal Sums time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 每周分享之cookie详解
本章从JS方向讲解cookie的使用.(实质上后端代码也是差不多用法,无非读取和设置两块) 基本用法:document.cookie="username=pengpeng"; 修改 ...
- #Leetcode# 836. Rectangle Overlap
https://leetcode.com/problems/rectangle-overlap/ A rectangle is represented as a list [x1, y1, x2, y ...