51nod 1285 山峰和分段

来源:互联网 发布:马云开淘宝网怎么赚钱 编辑:程序博客网 时间:2024/06/05 05:58

暴力枚举下就好了
假设初始用n个山峰,就从n开始枚举,枚举到1

#include<bits/stdc++.h>using namespace std;const int MAXN = 50010;int height[MAXN];int num[MAXN];int n,cnt;int main(){    ios::sync_with_stdio(false);    cin >> n;    for(int i = 1; i <= n; ++i)        cin >>height[i];    for(int i = 2; i < n; ++i)    {        if(height[i] > height[i-1] && height[i] > height[i+1])        {            num[i] = num[i-1]+1;            ++cnt;        }        else            num[i] = num[i-1];    }    num[n] = num[n-1];    int d;    bool flag;    int res = 0;    while(cnt--)    {        if(n%(cnt+1)) continue;        d = n/(cnt+1);        flag = true;        for(int i = d; i <= n; i = i+d)        {            if(num[i]-num[i-d] <= 0)            {                flag = false;                break;            }        }        if(flag)        {            res = cnt+1;            break;        }    }    cout << res <<endl;    return 0;}
原创粉丝点击