zoukankan      html  css  js  c++  java
  • 51nod 1414 冰雕 暴力

    题目来源: CodeForces
    基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题
     收藏
     关注

    白兰大学正在准备庆祝成立256周年。特别任命副校长来准备校园的装扮。

    校园的中心竖立着n个冰雕。这些雕像被排在一个等分圆上,因此他们形成了一个正n多边形。这些冰雕被顺针地从1到n编号。每一个雕有一个吸引力t[i].

    校长来看了之后表示不满意,他想再去掉几个雕像,但是剩下的雕像必须满足以下条件:

    ·        剩下的雕像必须形成一个正多边形(点数必须在3到n之间,inclusive),

    ·        剩下的雕像的吸引力之和要最大化。

    请写一个程序帮助校长来计算出最大的吸引力之和。如果不能满足上述要求,所有雕像不能被移除。

    Input
    单组测试数据。
    第一行输入一个整数n(3≤n≤20000),表示初始的冰雕数目。
    第二行有n个整数t[1],t[2],t[3],…,t[n],表示每一个冰雕的吸引力(-1000≤t[i]≤1000),两个整数之间用空格分开。
    Output
    输出答案占一行。
    Input示例
    8
    1 2 -3 4 -5 5 2 3
    6
    1 -2 3 -4 5 -6
    Output示例
    14
    9

    说好的3级题 结果一发暴力..
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <iomanip>
    #include <math.h>
    #include <map>
    using namespace std;
    #define FIN     freopen("input.txt","r",stdin);
    #define FOUT    freopen("output.txt","w",stdout);
    #define INF     0x3f3f3f3f
    #define INFLL   0x3f3f3f3f3f3f3f
    #define lson    l,m,rt<<1
    #define rson    m+1,r,rt<<1|1
    typedef long long LL;
    typedef pair<int, int> PII;
    using namespace std;
    
    const int maxn = 20005;
    
    int a[maxn];
    
    int main() {
        //FIN
        int n;
        while(~scanf("%d", &n)) {
            int sum = 0;
            for(int i = 1; i <= n; i++) {
                scanf("%d", &a[i]);
                sum += a[i];
            }
            int sum1 = 0;
            sum = -INF;
            for(int i = 1; n / i >= 3; i++) {
                if(n % i == 0) {
                    for(int j = 1; j <= i; j++) {
                        sum1 = 0;
                        for(int k = j; k <= n; k += i) sum1 += a[k];
                        sum = max(sum1, sum);
                    }
                }
            }
            printf("%d
    ", sum);
        }
    
        return 0;
    }
    

      

  • 相关阅读:
    56. Merge Intervals
    Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths CodeForces
    CodeForces 1328E-Tree Queries【LCA】
    2^x mod n = 1 HDU
    CodeForces 1327D
    CodeFoeces 1327E
    AtCoder Beginner Contest 159 E
    牛客14648-序列【莫比乌斯反演+容斥定理】
    完全平方数 HYSBZ
    MongoDB学习笔记(六、MongoDB复制集与分片)
  • 原文地址:https://www.cnblogs.com/Hyouka/p/7448334.html
Copyright © 2011-2022 走看看