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. Microsoft SQL Server 2008 R2官方中文版(SQL2008下载)

    Microsoft SQL Server 2008 R2官方中文版(SQL2008下载) http://www.2cto.com/database/201308/235349.html

  2. 5分钟连续出现某现象+微信模板消息提醒 PHP

    需求场景:用电插座电流连续出现5次电流过高(大于 3A)后停止用电服务,前四次发送电流过高提醒,最后一次发送结束用电服务提醒 思路: Redis  key 设为:插座编号+user户编号  value ...

  3. 【HANA系列】SAP HANA启动出现ERROR

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA启动出现ERRO ...

  4. <每日一题> Day4:CodeForces-1042A.Benches(二分 + 排序)

    题目链接 参考代码: /* 排序 + 每次取小 #include <iostream> #include <algorithm> using namespace std; co ...

  5. jvm学习(2)JVM内存说明

    前言 一.类方法 类方法是静态方法,前面需要有static修饰符修饰.类方法内不能涉及有关变量的内容1.不能调用类的对象方法2.不能引用对象变量3.类方法不能被重写(覆盖)4.类方法不能使用super ...

  6. python学习shutil模块的文件压缩和解压用法

    shutil模块可以创建压缩包并返回文件路径,例如 zip,tar,下面详细其用法 base_name 压缩包的文件名,也可以是压缩包的路径,只是文件名时,则保存至当前目录,否则保存指定路径 data ...

  7. 【问题解决方案】git clone失败的分析和解决

    参考链接 git_clone资源获取失败解决 使用Git clone代码失败的解决方法 [Git] Clone failed 克隆失败的解决方法 问题描述: 无论是git clone还是pull,均失 ...

  8. React框架新闻网站学习过程中遇到的错误总结

    1.安装指定版本插件命令 npm install 插件名字@1.1.4(版本号) --save 或 yarn add 插件名字@1.1.4(版本号) --dev 2.Error:‘Link’ is n ...

  9. 只要三步,你就可以在github上发布网站了

    今天,看到github推送了一个新的消息,Publishing with GitHub Pages, now as easy as 1, 2, 3.总结起来就是在github将你的文档或者发布网页将会 ...

  10. SwiftUI 里的 swift 闭包总结

    创建 UI 时的闭包使用 在 SwiftUI 里闭包出现的频率特别高,这里我重新梳理了下闭包的定义. 关于闭包 闭包表达式语法的一般形式如下: {(parameters) -> return t ...