codeforces D. 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,?...,?tnti —
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.

Sample test(s)

input

8
1 2 -3 4 -5 5 2 3

output

14

本题还是有一定难度的。

注意点:

1 要使用逆向思维,不是要计算melt掉多少sculptures, 而是要计算需要剩下多少个sculptures

2 所有情况都需要考虑到,最大间隔melt掉的sculptures是n/3个

3 要判断这样间隔melt掉sculptures之后,剩下的sculptures是否能组成多边形

要很仔细想清楚才能做出来。

It is never too careful to scrutinize a problem!

It is never too careful to design an algorithm!

#include <vector>
#include <iostream>
using namespace std;

void IceSculptures()
{
	unsigned n;
	cin>>n;
	vector<int> sculptures(n);
	for (unsigned i = 0; i < n; i++)
	{
		cin>>sculptures[i];
	}
	int curSum = 0, maxSum = (1<<31);
	for (unsigned span = 1; span <= n / 3; span++)
	{
		if (n % span) continue;
		for (unsigned b = 0; b < span; b++)
		{
			curSum = 0;
			for (unsigned i = b; i < n; i += span)
			{
				curSum += sculptures[i];
			}
			maxSum = curSum > maxSum? curSum : maxSum;
		}
	}
	cout<<maxSum;
}

codeforces D. Ice Sculptures 题解,码迷,mamicode.com

时间: 2024-08-19 05:55:10

codeforces D. Ice Sculptures 题解的相关文章

codeforces A. Supercentral Point 题解

One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points(x1,?y1),?(x2,?y2),?...,?(xn,?yn). Let's define neighbors for some fixed point from the given set (x,?y): point (x',?y') is (x,?y)'s right neighbor,

codeforces New Year Present 题解

The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception. Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a r

codeforces Sereja and Dima 题解

Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take o

Educational Codeforces Round 64部分题解

Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点个数是否有限,如果有限,输出. 很明显当正方形套三角形或者三角形套正方形是交点个数是无限的(因为有一条边相交) 其他图形的嵌套交点个数比较好判断,不多赘述 但是注意坑点: 当按照矩形,园,三角这样的顺序是,三角与圆的一个交点是与圆和正方形的交点重合的,判一下就好了 #include<cstdio>

Codeforces 7E - Defining Macros 题解

目录 Codeforces 7E - Defining Macros 题解 前言 做法 程序 结尾 Codeforces 7E - Defining Macros 题解 前言 开始使用博客园了,很想写点东西.(逃 这是一道Codeforces题目. 做法 一道大模拟 相信大家都看得懂题目意思,我就不赘述了. 首先我们读进来\(n\)行,对于每一行,我们把它初步分成一下四块内容: #号 define 宏的名字 宏的表达式 注意:#和define中间可能会有空格,define和宏的名字,宏的名字和宏

CodeForces 540C Ice Cave (BFS)

http://codeforces.com/problemset/problem/540/C Ice Cave Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 540C Description You play a computer game. Your character stands on some level of

CodeForces 804C Ice cream coloring

Ice cream coloring 题解: 这个题目中最关键的一句话是, 把任意一种类型的冰激凌所在的所有节点拿下来之后,这些节点是一个连通图(树). 所以就不会存在多个set+起来之后是一个新的完全图. 所以只要直接去做就好了. 对于每个节点来说,染色. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freope

Codeforces Round #616 部分题解

老年选手诈尸? A,B 咕了. C - Prefix Enlightenment 很容易看出这个限制条件可以推出每个点最多被两个集合包含.按照套路,很容易联想到给这两个集合连一条边,表示他们的状态要相同/不同. 因为保证了有解,所以从左往右扫的时候拿并查集维护一下每个连通块的二分图情况,选较小的那一边. 如果只被一个集合覆盖,那么就相当于强制这个集合选/不选,在做并查集的时候特判一下即可. 代码咕了. D - Coffee Varieties (hard version) 作为一名憨憨,做法当然

【codeforces】【比赛题解】#854 CF Round #433 (Div.2)

cf一如既往挺丧 看丧题点我! [A]分数 Petya是数学迷,特别是有关于分数的数学.最近他学了所谓一个分数被叫做"真分数"当且仅当其分子小于分母,而一个分数被叫做"最简分数"当且仅当其分子分母互质.在闲暇时间,Petya在用计算器研究:如何把最简真分数转换为小数等问题.有一天他不小心把除号(÷)按成了加号(+),导致他得到了分子与分母的和.Petya想要得到他原来的分数,但他很快发现这不是唯一的.所以现在他想要知道最大的最简真分数使得其分子与分母的和为n. 输入