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
 
Recommend
wange2014   |   We have carefully selected several similar problems for you:  6343 6342 6341 6340 6339 
 
 
 #include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 201314
#define mod 530600414
#define gep(i,a,b) for(int i=a;i<=b;i++)
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
int t,id;
ll f[N+],c[N+],s[N+],n[N+];
/*
f ; 任意两个c的坐标差之和
c : 字符串里c的个数
s : 字符串里所有的c的坐标和
n ; 字符串的长度
例如 :
cffffcff ffcffcffffcff
((8-6)+(8-1))*3
3*2+6*2+11*2
上面两个式子的和==f[7]
(1+6)+(3+6+11)+8*3==s[7]
*/ void init()
{
c[]=,s[]=,n[]=,f[]=;
c[]=,s[]=,n[]=,f[]=;
gep(i,,N){
f[i]=( (f[i-]+f[i-])%mod + (((c[i-]*n[i-]-s[i-])%mod+mod)%mod)*c[i-]%mod +(c[i-]*s[i-]%mod) )%mod;
c[i]=(c[i-]+c[i-])%mod;
n[i]=(n[i-]+n[i-])%mod;
s[i]=((s[i-]+s[i-])%mod+(c[i-]*n[i-])%mod)%mod;
//if(i<=12)printf("%lld %lld %lld %lld\n",f[i],c[i],n[i],s[i]);
}
}
int main()
{
init();
scanf("%d",&t);
gep(i,,t){
scanf("%d",&id);
printf("Case #%d: %lld\n",i,f[id]);
}
return ;
}
 

hdu 5459的更多相关文章

  1. 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的距离是多少? 解题思路: 直觉告诉我 ...

  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(递推)

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

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

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

  5. hdu 5459(递推好题)

    Jesus Is Here Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)To ...

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

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

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

    大意: 定义$f_1="c",f_2="ff",f_n=f_{n-2}+f_{n-1}$, 求所有"cff"的间距和. 记录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. 073 Set Matrix Zeroes 矩阵置零

    给定一个 m x n 的矩阵,如果一个元素为 0 ,则将这个元素所在的行和列都置零.你有没有使用额外的空间?使用 O(mn) 的空间不是一个好的解决方案.使用 O(m + n) 的空间有所改善,但仍不 ...

  2. Auto yes to the License Agreement on sudo apt-get -y install oracle-java7-installer

    参考一 参考二 我自己的做法是: && add-apt-repository ppa:webupd8team/java \ && apt-get update \ &a ...

  3. Jexus~docker与它产生了暖味

    前段时间写了很多docker for .net core的文章,用来快速部署微服务相当给力,而尝到了香头的我们希望把.net frameworks的程序也使用docker来部署一下,那么接下来我就结果 ...

  4. Java浏览器下载文件为excel(springMVC方式)

    action中的方法 /** * Excel文件下载处理 * @return */ @RequestMapping("/downloanExcel") public ModelAn ...

  5. JAVA基础之网络通信协议--TCP与UDP

    个人理解: 了解区分UDP与TCP的不同,正常情况都是两者结合的使用模式!为了更好的传输,经常会开多线程进行传输的! 一.网络通信协议: 1.TCP/IP协议: 四层:应用层.传输层.网络层和链路层: ...

  6. JavaScirpt 的垃圾(garbage collection)回收机制

    一.垃圾回收机制—GC Javascript具有自动垃圾回收机制(GC:Garbage Collecation),也就是说,执行环境会负责管理代码执行过程中使用的内存. 原理:垃圾收集器会定期(周期性 ...

  7. JS将人民币小写金额转换为大写

    /** 数字金额大写转换(可以处理整数,小数,负数) */ function smalltoBIG(n) { var fraction = ['角', '分']; var digit = ['零', ...

  8. PHPStorm2017.1.3永久激活方法之本地破解激活

    是时候升级你的phpstorm了,咱们马上行动! 下载 1.phpstorm https://www.jetbrains.com/phpstorm/download/ 2.破解包 破解补丁无需使用注册 ...

  9. 2、HTTP状态码

    HTTP状态码 当浏览者访问一个网页时,浏览者的浏览器会向网页所在服务器发出请求.当浏览器接收并显示网页前,此网页所在的服务器会返回一个包含HTTP状态码的信息头(server header)用以响应 ...

  10. iOS优化

    load妙用 aop面向切面编程 NSNumber Or Int @()适配64位 经过漫长时间的学习 你终于掌握了iOS大法 你找到了份iOS开发的工作 信誓旦旦的要开始你的coding生涯 老板对 ...