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的更多相关文章
随机推荐
- [MicroPython]TurniBit开发板旋转按钮控制脱机摆动
一.实验目的: ?学习在PC机系统中扩展简单I/O 接口的方法 ?学习TurnipBit拼插编程 ?了解舵机工作原理 ?学习TurnipBit扩展板舵机和旋转按钮接线方式 二.所需原器件: ?Turn ...
- object detection[content]
近些年,随着DL的不断兴起,计算机视觉中的对象检测领域也随着CNN的广泛使用而大放异彩,其中Girshick等人的<R-CNN>是第一篇基于CNN进行对象检测的文献.本文欲通过自己的理解来 ...
- Vscode的python配置(macOS)
_ 1. Vscode是一款开源的跨平台编辑器.默认情况下,vscode使用的语言为英文(en),以下步骤改为中文 打开vscode工具,使用快捷键组合[Cmd+Shift+p],在搜索框中输入“co ...
- ASP.NET Core中代码使用X509证书,部署到IIS上后报错:System cannot find the specified file 的解决办法(转载)
问: I am trying to embrace the mysteries of SSL communication and have found a great tutorial on this ...
- odoo11登录之后返回的session信息分析
{ "id": null, "jsonrpc": "2.0", "result": { "web_tours& ...
- 关于学习JAVA第二章的心得
这章主要讲了JAVA的变量,数据类型和运算符的使用方法及规则. 其实在大一的时候接触过一点C和C++的知识所以对变量,数据类型,运算符还是有一定了解的. 变量其实就是存储数据的空间.我们每次使用某一种 ...
- 用Java执行Python:Jython踩坑笔记
常见的java调用python脚本方式 1.通过Jython.jar提供的类库实现 2.通过Runtime.getRuntime()开启进程来执行脚本文件 1.Jython Jpython使用时,版本 ...
- .Net Core 在 Linux-Centos上的部署实战教程(一)
pa我是在VS2017上写好项目然后来部署的,我的宗旨能截图就少BB 服务器系统: Asp.Net Core版本: 1.往服务器安装.net core 2.1 https://www.microsof ...
- DSL 系列(1) - 扩展点的论述与实现
前言 DSL 全称为 domain-specific language(领域特定语言),本系列应当会很长,其中包含些许不成熟的想法,欢迎私信指正. 1. DSL 简述 我理解的 DSL 的主要职能是 ...
- vue文档全局api笔记1
全局api方法 1.Vue.extend(options) 请注意,extend创建的是一个组件构造器,而不是一个具体的组件实例.所以他不能直接在new Vue中这样使用: new Vue({comp ...