Jesus Is Here

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

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=si−2+si−1 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 (1≤T≤100), indicating there are T test cases.
Following T lines, each line contain an integer n (3≤n≤201314), 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"(j−i) 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
 题意:s1 = c,s2 = ff,递推,当i>=3,i等于i-2加上i-1构成,即s3 = cff,问第n个字符串中所有c字符的下标差值
第i个字符串的所有c字符的下标差值肯定由i-1的串还有i-2的串的计算过来的,然而怎么计算……需要什么定义什么,让计算机干什么
你想计算下标差值,这么多数,i-1,i-2,定义-数组把所有的下标和存起来,当算i-1和i-2串的差值计算的时候分两步,算i-2串到串末的距离加上i-1串的距离就等于i-1和i-2串差值
 *****************************************************************************************************************************

ans[i]             =               ans[i-1]+ans[i-2]   +                                       (len[i-2]*num[i-2]-sum[i-2])*num[i-1]                  +                     sum[i-1]*num[i-2];

i  字符串中所有c字符差值 = i-1和i-2差值之和,再加上i-1中的c和i-2中的c的差值, (= 所有 i-2 中的c的下标到i-2串末尾的距离   +  i-1串的和*i-2中c的数量

i-2中的c下标到i-2末尾的距离,就等于i-2中c字符 个 总长度减去c字符的下标之和

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<math.h>
#include<algorithm> using namespace std; const int maxn = ; #define mod 530600414
#define INF 0x3f3f3f3f long long num[maxn], sum[maxn], len[maxn], ans[maxn];
// num是该下标表示的字符串中c的个数,sum是所有c下标之和,len是字符串长度,ans是所有下标差值之和
int main()
{
int t, x;
num[] = len[] = sum[] = ;
len[] = ;
sum[] = num[] = ;
for(int i = ; i < maxn; i++)
{
num[i] = (num[i-] + num[i-])%mod;
len[i] = (len[i-] + len[i-])%mod;
sum[i] = ((sum[i-] + sum[i-])%mod + (len[i-]*num[i-])%mod)%mod; //sum表示c下标和,因为i-1串放在了i-2串的后边,所以sum要加上i-1串中的数量*i-2串的长度,就是i串中所有c的下标和
ans[i] = (ans[i-]%mod + ans[i-]%mod + (num[i-]%mod*len[i-]%mod - sum[i-]%mod)%mod*num[i-]%mod+num[i-]%mod*sum[i-]%mod)%mod;
}
scanf("%d", &t);
for(int i = ; i <= t; i++)
{
scanf("%d", &x);
printf("Case #%d: %I64d\n", i, ans[x]);
}
return ;
}

Jesus Is Here的更多相关文章

  1. hdu 5459 Jesus Is Here (费波纳茨递推)

    Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)Total Submission ...

  2. hdu 5459 Jesus Is Here 数学

    Jesus Is Here Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  3. Hdu 5459 Jesus Is Here (2015 ACM/ICPC Asia Regional Shenyang Online) 递推

    题目链接: Hdu 5459 Jesus Is Here 题目描述: s1 = 'c', s2 = 'ff', s3 = s1 + s2; 问sn里面所有的字符c的距离是多少? 解题思路: 直觉告诉我 ...

  4. hdu5459 Jesus Is Here

    Problem Description I've sent Fang Fang around 201314 text messages in almost 5 years. Why can't she ...

  5. HDU 5459 Jesus Is Here(递推)

    http://acm.hdu.edu.cn/showproblem.php?pid=5459 题意: S(1) = c,S(2) = ff, S(3) = cff,之后S(i) = S(i-1)+S( ...

  6. J - Jesus Is Here HDU - 5459 (递推)

    大意: 定义$f_1="c",f_2="ff",f_n=f_{n-2}+f_{n-1}$, 求所有"cff"的间距和. 记录c的个数, 总长 ...

  7. hdu 5459(2015沈阳网赛) Jesus Is Here

    题目;http://acm.hdu.edu.cn/showproblem.php?pid=5459 题意 给出一组字符串,每个字符串都是前两个字符串相加而成,求第n个字符串的c的各个坐标的差的和,结果 ...

  8. ACM学习历程—HDU 5459 Jesus Is Here(递推)(2015沈阳网赛1010题)

    Sample Input 9 5 6 7 8 113 1205 199312 199401 201314 Sample Output Case #1: 5 Case #2: 16 Case #3: 8 ...

  9. HDU 5459 Jesus Is Here (递推,组合数学)

    有点麻烦的递推,递推的原则:向小的问题方向分解,注意边界. 字符串的递推式为 定义f为Si中的总方案数 首先可以得到 fi=fi-1+fi-2+组合(si-2,si-1) 然后考虑Si-2和Si-1之 ...

随机推荐

  1. 【ABAP系列】SAP VA02修改销售订单的BAPI举例

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP VA02修改销售订单的B ...

  2. Windows操作系统命令整理-Win7

    注册表(Windows95以后Windows系统版本,windows server中regedit和regedit32合并为一个新的编辑器,名称仍然是regedit) HKEY_LOCAL_MACHI ...

  3. 16 (H5*) JS第6天 日期、字符串、数组

    目录 1:date 2:格式化日期 3:字符串 4:字符串的方法 5:字符串的案例 6:数组的方法 7:包装类型 复习 正文 1:日期:date <script> //创建实例对象 // ...

  4. SQL查询结果增加序列号

    SQL查询记录中增加序列号 根据学生成绩在查询结果中增加排名字段: 1.SELECT ROW_NUMBER() OVER (ORDER BY SCORE ASC) AS RANK,NAME,SCORE ...

  5. document.domain location.hostname location.host

    document.domain    location.hostname     location.host   :https://www.cnblogs.com/shd-study/p/103031 ...

  6. 16、前端知识点--Object.defineProperty 的用法+双向数据绑定原理解析

    一.Object.defineProperty 的用法 Object.defineProperty 可以用于给对象添加更新属性. <script> // Object.defineProp ...

  7. latex算法步骤如何去掉序号

    想去掉latex算法步骤前面的序号,如下 我想去掉每个算法步骤前面的数字序号,1,2,3,因为我已经写了step.我们只需要引用a lgorithmic这个包就可以了,代码如下: \usepackag ...

  8. 2018-8-10-win10-uwp-读写XML

    title author date CreateTime categories win10 uwp 读写XML lindexi 2018-08-10 19:16:51 +0800 2018-2-13 ...

  9. 按字节读取txt文件缓存区大小设置多少比较好?

    读取 txt 文件常规写法有逐行读取和按照字节缓存读取,那么按照字节缓存读取时,设置缓存区多大比较好呢?百度了一下,没发现有说这个问题的,自测了一把,以事实说话. 常规读取方法如下: // 字节流读取 ...

  10. Linux下安装Dubbox

    1.Dubbox简介 Dubbox 是一个分布式服务框架,其前身是阿里巴巴开源项目Dubbo ,被国内电商及互联网项目中使用,后期阿里巴巴停止了该项目的维护,当当网便在Dubbo基础上进行优化,并继续 ...