hdu5459 Jesus Is Here(沈阳网赛)

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 s1=c" and the second one is s2=ff" .
The i -th message is si=si2+si1 afterwards. Let me give you some examples.
s3=cff" , s4=ffcff" and s5=cffffcff" .

``I found the i -th message's utterly charming," Jesus said.
``Look at the fifth message". s5=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:sn[i..i+2]=sn[j..j+2]=cff"(ji) mod 530600414,

where sn 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,字符总个数为n 2
        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;
}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值