码迷,mamicode.com
首页 > 其他好文 > 详细

hdu5459 Jesus Is Here(沈阳网赛)

时间:2015-09-21 17:58:01      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:网络赛   dp   

Jesus Is Here

Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others)
Total Submission(s): 257 Accepted Submission(s): 175


Problem Description
I‘ve sent Fang Fang around 201314 text messages in almost 5 years. Why can‘t she make sense of what I mean?
``But Jesus is here!" the priest intoned. ``Show me your messages."
Fine, the first message is s技术分享1技术分享=c"技术分享 and the second one is s技术分享2技术分享=ff"技术分享.
The i技术分享-th message is s技术分享i技术分享=s技术分享i?2技术分享+s技术分享i?1技术分享技术分享 afterwards. Let me give you some examples.
s技术分享3技术分享=cff"技术分享, s技术分享4技术分享=ffcff"技术分享 and s技术分享5技术分享=cffffcff"技术分享.

``I found the i技术分享-th message‘s utterly charming," Jesus said.
``Look at the fifth message". s技术分享5技术分享=cffffcff"技术分享 and two cff"技术分享 appear in it.
The distance between the first cff"技术分享 and the second one we said, is 5技术分享.
``You are right, my friend," Jesus said. ``Love is patient, love is kind.
It does not envy, it does not boast, it is not proud. It does not dishonor others, it is not self-seeking, it is not easily angered, it keeps no record of wrongs.
Love does not delight in evil but rejoices with the truth.
It always protects, always trusts, always hopes, always perseveres."

Listen - look at him in the eye. I will find you, and count the sum of distance between each two different cff"技术分享 as substrings of the message.

Input
An integer T (1T100)技术分享, indicating there are T技术分享 test cases.
Following T技术分享 lines, each line contain an integer n (3n201314)技术分享, as the identifier of message.

Output
The output contains exactly T技术分享 lines.
Each line contains an integer equaling to:
技术分享i<j:s技术分享n技术分享[i..i+2]=s技术分享n技术分享[j..j+2]=cff"技术分享(j?i) mod 530600414,技术分享

where s技术分享n技术分享技术分享 as a string corresponding to the n技术分享-th message.

Sample Input
9 5 6 7 8 113 1205 199312 199401 201314

Sample Output
Case #1: 5 Case #2: 16 Case #3: 88 Case #4: 352 Case #5: 318505405 Case #6: 391786781 Case #7: 133875314 Case #8: 83347132 Case #9: 16520782

Source

题意:求第n项中所有字符‘c‘的坐标差的和。
分析:每一个新的字符串都是由前两个字符串合成的,所以得到这个公式:ans[n]=ans[n-1]+ans[n-2]+X(X表示两个字符串连接后增加的值);假设第n-2项中字符‘c‘的个数为c1,字符‘c‘坐标之和为s1,字符总个数为n1,第n-1项中字符‘c‘的个数为c2,字符‘c‘坐标之和为s2,字符总个数为n2
        1、对于n-1这个串里的每个’c‘所增加的值为n-2中’c‘的反向坐标(就是串长 - 坐标,记为cc ),即c2*(c1*n1-s1);(把c1*n1-s1 拆分成一个一个的c相加,就相当于c1个cc相加)
2、对于n-2这个串里的每个’c‘所增加的值就为n-1中’c‘的坐标,即c1*s2。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 530600414;
#define ll long long
#define CL(a) memset(a,0,sizeof(a))

ll ans[300000];//答案
ll c[300000];//c的个数
ll s[300000];//c的坐标和
ll d[300000];//长度

int main()
{
    ans[1]=0; ans[2]=0; ans[3]=1;
    ans[4]=1; c[4]=1; s[4]=3; d[4]=3;
    ans[5]=5; c[5]=2; s[5]=7; d[5]=5;
    ans[6]=16; c[6]=3; s[6]=20; d[6]=8;
    for(int i=7; i<=201314; i++)
    {
        ans[i]=(ans[i-1]+ans[i-2]+(((c[i-2]*d[i-1]-s[i-2])%MOD)*c[i-1])%MOD+(c[i-2]*s[i-1])%MOD)%MOD;
        c[i]=(c[i-1]+c[i-2])%MOD;
        s[i]=(s[i-1]+s[i-2]+c[i-1]*d[i-1])%MOD;//第(i-1)个字符串里的c坐标都要加上第(i-2)个串的长度
        d[i]=(d[i-1]+d[i-2])%MOD;
    }

    int T,n;
    scanf ("%d",&T);
    for(int cas=1; cas<=T; cas++)
    {
        scanf ("%d",&n);
        printf ("Case #%d: ",cas);
        printf ("%lld\n",ans[n]);
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

hdu5459 Jesus Is Here(沈阳网赛)

标签:网络赛   dp   

原文地址:http://blog.csdn.net/d_x_d/article/details/48626727

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!