Codeforces 158 D
题目链接 :http://codeforces.com/contest/158/problem/D
3 seconds
256 megabytes
standard input
standard output
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.
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.
Print the required maximum sum of the sculptures' attractiveness.
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
In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.
题目大意 :
题目大意 :
很多个雕像围在一起构成一个多边形,每一个占一个点并有个分数。现在需要移除一些雕像,使分数和最大,并且还是能构成多边形。
枚举每次删除的步长l,然后维护一个最大值就好了。枚举步长的上界是l * 3 <= n。
代码 :
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
const int MaxN = 2e4;
using namespace std;
int n;
int ans;
int a[MaxN + 5];
int main()
{
scanf("%d",&n);
for(int i = 1;i <= n;i++){
scanf("%d",&a[i]);
ans += a[i];
}
for(int i = 1;i <= n / 3;i++){ // 枚举步长到n / 3
if(n % i ) continue;
for(int j = 1;j <= i;j++){ // 每次枚举的起始位置小于当前枚举步长
int s = 0;
for(int k = j;k <= n;k += i){
s += a[k]; //求每次枚举的和
}
ans = max(ans,s); //维护最大值
}
}
printf("%d\n",ans);
}
Codeforces 158 D的更多相关文章
- Codeforces 158 B. Taxi[贪心/模拟/一辆车最多可以坐4人同一个群的小朋友必须坐同一辆车问最少需要多少辆车]
http://codeforces.com/problemset/problem/158/B B. Taxi time limit per test 3 seconds memory limit pe ...
- CodeForces 158 B. Taxi(模拟)
[题目链接]click here~~ [题目大意]n组团体去包车,每组团体的人数<=4,一辆车最多容纳4人,求所求车的数目最小 [解题思路]:思路见代码~~ // C #ifndef _GLIB ...
- Codeforces Round #158 (Div. 2)
A. Adding Digits 枚举. B. Ancient Prophesy 字符串处理. C. Balls and Boxes 枚举起始位置\(i\),显然\(a_i \le a_j, 1 \l ...
- Codeforces Round #158 (Div. 2) C. Balls and Boxes 模拟
C. Balls and Boxes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces 158E Phone Talks
http://codeforces.com/contest/158/problem/E 题目大意: 麦克是个名人每天都要接n电话,每通电话给出打来的时间和持续时间,麦克可以选择接或不接,但是只能不接k ...
- codeforces C. Cd and pwd commands 执行命令行
执行命令来改变路径 cd 并显示路径命令 pwd 一个节目的 抽样: input 7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd ou ...
- Codeforces 158E Phone Talks:dp
题目链接:http://codeforces.com/problemset/problem/158/E 题意: 你有n个电话要接,每个电话打进来的时刻为第t[i]分钟,时长为d[i]分钟. 每一个电话 ...
- codeforces E. Phone Talks(dp)
题目链接:http://codeforces.com/contest/158/problem/E 题意:给出一些电话,有打进来的时间和持续的时间,如果人在打电话,那么新打进来的电话入队,如果人没有打电 ...
- [题解]Codeforces Round #254 (Div. 2) A - DZY Loves Chessboard
链接:http://codeforces.com/contest/445/problem/A 描述:一个n*m的棋盘,有一些格子不能放棋子.现在把黑白棋子往上放,要求放满且相邻格子的棋子颜色不同.输出 ...
随机推荐
- 腾讯QQ音乐网页版 音频初始化模块解压混淆js源码
define("js/view/playerBar.js",function(t,e,o){ var i = t("js/lib/zepto.js"), a = ...
- C# 截取图片区域,并返回所截取的图片
/// <summary> /// 截取图片区域,返回所截取的图片 /// </summary> /// <param name="SrcImage" ...
- Tomcat7.0更改默认的路径来访问自己的项目
如何使自己的项目没有输入:localhost:8080/项目名称/index.html 能够访问. 步骤,如下面的 : 找到tomcat --- config----server.xml 选中右键编 ...
- leetcode第35题--Valid Sudoku
题目:Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could ...
- 单极型ADC如何测量负电压?
最常用的方法是使用一个运放做成加法器将负电压抬到0V以上,如果这样的输出超过了最大输出电压那么再使用比例衰减就可以办到了. 参考下面的讨论: http://www.amobbs.com/thread- ...
- Singal Page App:使用Knockout和RequireJS创建高度模块化的单页应用引擎
Singal Page App 开篇扯淡 距离上一篇文章已经有好几个月,也不是没有时间记录点东西,主要是换了新的工作,在一家外资工作,目前的工作内容大多都是前端开发,新接触的东西因为时间原因,大多还不 ...
- mysql 安装后无法登陆mysql的 shell 那mysql>经验:ERROR 1045 (28000): Access denied for user 'root'@'localhost‘
[root@hzswtb2-mpc ~]# mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using pas ...
- 站点维护使用app_offline.htm页面提供友好的更新提示
进行站点维护时为了以一个友好的方式提示给用户,比如什么“本网站正在更新”等等的信息可以建立一个叫app_offline.htm 的静态HTM页面文件,其中修改成你要临时显示的内容,将其放在你的应用的根 ...
- 开启apache服务
安装后如果需要手动添加Sevice,可以按照如下方法: Apache版本:httpd-2.2.15_win32 Apache Service Monitor 提示:“No services insta ...
- 输出,变量的使用,子查询,逻辑语句,循环,case..when..then..end多分支语句,Exists(判断存在)
--------------输出----------------print 'hello world'--以文本形式输出select 'hello world'--以网格形式输出,也可以设置成以文本形 ...