【BZOJ 3613】 [Heoi2014]南園滿地堆輕絮,bzojheoi2014

來源:互聯網
上載者:User

【BZOJ 3613】 [Heoi2014]南園滿地堆輕絮,bzojheoi2014
3613: [Heoi2014]南園滿地堆輕絮

Time Limit: 50 Sec Memory Limit: 256 MB
Submit: 167 Solved: 109
[Submit][Status][Discuss]
Description

小 Z 是 ZRP(Zombies’ Republic of Poetry,殭屍詩歌共和國)的一名詩歌愛好者,最近 他研究起了詩詞音律的問題。
在過去,詩詞是需要編成曲子唱出來的,比如下面這首《菩薩蠻》,唱出來的話其對應 的音符就是這樣的:
南 園 滿 地 堆 輕 絮, 愁 聞 一 霎 清 明 雨
1 1 5 5 6 6 5 4 4 3 3 2 2 1
因而可以發現,“1 1 5 5 6 6 5 4 4 3 3 2 2 1”這串音符就成為了研究音律的關鍵。
小 Z 翻閱了眾多史料發現,過去的一首曲子的音調是不下降的
小 Z 想要知道對於一首給定的曲子,如何通過提高音調或者降低音調,將它的音調修改 的不下降,
而且使得修改幅度最大的那個音符的修改幅度盡量小。
即如果把一個包含 n 個音 符的曲子看做是一個正整數數列 A[1]…A[n],
那麼 目標是求另一個正整數數列 B[1]…B[n], 使得對於任意的 1≤i

#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <cstdlib>#define LL long longusing namespace std;int n,a[5000005],mod;LL sa,sb,sc,sd;int F(LL x){    return (x*x%mod*x%mod*sa%mod+sb*x%mod*x%mod+sc*x%mod+sd)%mod;}int ok(int x){    int pre=a[1]-x;    for (int i=2;i<=n;i++)    {        if (a[i]+x>=pre)        {            if (pre<a[i]-x) pre=a[i]-x;        }        else return 0;    }    return 1;}int main(){    cin>>n>>sa>>sb>>sc>>sd>>a[1]>>mod;    a[0]=0;    for (int i=2;i<=n;i++)        a[i]=(int)((F(a[i-1])+F(a[i-2]))%mod+mod)%mod;    int ans,l=0,r=mod+5;    while(l<=r)    {        int m=(l+r)>>1;        if (ok(m)) ans=m,r=m-1;        else l=m+1;    }    cout<<ans<<endl;    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.