Jesus Is Here

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5459

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: 3
Case #2: 2
Case #3: 2
Case #4: -1
Case #5: 2
Case #6: 4
Case #7: 1
Case #8: -1

HINT

题意

f1=c,f2=ff,fn = fn-1+fn-2

然后问你每对cff之间的距离和加起来是多少

题解:

暴力找规律,然后类似fib数列一样递推

不断归纳就好了……

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring> using namespace std; const int N=;
const long long pr=;
long long sum[N],pre[N],tot[N],suf[N],s[N],f[N]; int main()
{
s[]=3LL;s[]=4LL;
pre[]=5LL;pre[]=8LL;
sum[]=5LL;sum[]=11LL;
suf[]=5LL;suf[]=8LL;
tot[]=5LL;tot[]=13LL;
f[]=5LL;f[]=16LL;
for(int i=;i<N;i++)
{
s[i]=(s[i-]+s[i-]-1LL)%pr;
if(i&)
{
pre[i]=(pre[i-]+pre[i-]+)%pr;
suf[i]=(suf[i-]+suf[i-]+)%pr;
sum[i]=(sum[i-]+(s[i-]-)*(pre[i-]+)+sum[i-])%pr;
tot[i]=(tot[i-]+(s[i-]-)*(suf[i-]+)+tot[i-])%pr;
f[i]=(f[i-]+f[i-]+(s[i-]-)*(s[i-]-)*+tot[i-]*(s[i-]-)+sum[i-]*(s[i-]-))%pr;
}
else
{
pre[i]=(pre[i-]+pre[i-]+)%pr;
suf[i]=(suf[i-]+suf[i-]+)%pr;
sum[i]=(sum[i-]+(s[i-]-)*(pre[i-]+)+sum[i-])%pr;
tot[i]=(tot[i-]+(s[i-]-)*(suf[i-]+)+tot[i-])%pr;
f[i]=(f[i-]+f[i-]+(s[i-]-)*(s[i-]-)*+tot[i-]*(s[i-]-)+sum[i-]*(s[i-]-))%pr;
}
// cout<<i<<" "<<s[i]<<" "<<pre[i]<<" "<<sum[i]<<" "<<tot[i]<<" "<<f[i]<<endl;
}
int T;
long long n;
scanf("%d",&T);
for(int cas=;cas<=T;cas++)
{
scanf("%d",&n);
printf("Case #%d: %I64d\n",cas,f[n]);
}
}

hdu 5459 Jesus Is Here 数学的更多相关文章

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

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

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

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

  4. 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 ...

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

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

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

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

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

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

  8. 2017"百度之星"程序设计大赛 - 复赛1003&&HDU 6146 Pokémon GO【数学,递推,dp】

    Pokémon GO Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. HDU 5810 Balls and Boxes 数学

    Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

随机推荐

  1. 中国海洋大学第四届朗讯杯高级组 A 2718 Rocky(模拟)

    题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2718 题意:优先直走,右 左 后.... ...

  2. bzoj1001

    平面图求最小割: 其实看bzoj1001一开始着实把我怔住了 AC的人暴多,可自己完全没思路 后来看了某大牛的ppt,才会做 一个月前做这题的吧,今天来简单回忆一下: 首先是欧拉公式 如果一个连通的平 ...

  3. bzoj1588,1208,1503

    进入splay tree的学习中: 据说splay tree在理论上功能十分强大,好好学: splay首先一定是一棵BST,所以记不得的时候画个图就明白: 首先总结一下splay基本的操作左旋,右旋: ...

  4. 【App FrameWork】框架的页面布局

    之前主要用JqueryMobile+PhoneGap的模式开发移动应用,但JQueryMobile自身存在的硬伤太多,如加载速度缓慢,页面转场白屏.闪烁,头尾部导航浮动问题,页面滚动等等,用户体验效果 ...

  5. I.MX6 bq27441 driver hacking

    /************************************************************************* * I.MX6 bq27441 driver ha ...

  6. CSS布局中——导航是非常常见的

    导航绝对是页面布局中最常见的,为了不用每次去写,稍微贴个简单的导航模版出来,方便以后使用. <title>CSS菜单</title> <style type=" ...

  7. HDU 5700 区间交 线段树暴力

    枚举左端点,然后在线段树内,更新所有左边界小于当前点的区间的右端点,然后查线段树二分查第k大就好 #include <cstdio> #include <cstring> #i ...

  8. Java中线程顺序执行

    现有线程threadone.threadtwo和threadthree,想要的运行顺序为threadone->threadtwo->threadthree,应该如何处理?这里需要用到一个简 ...

  9. ajax跨域解决方案(服务端仅限java)

    楼主前端知识菜鸟,高手勿喷,在此记录工作中遇到的问题及解决方案,大神请滤过 方法1.jsonp(js客户端ajax请求参数方式设置) 方法2.服务端接口设置: HttpServletResponse ...

  10. ruby 资料整理

    http://blog.csdn.net/maingalaxy/article/details/46013393 http://blog.csdn.net/dzl84394/article/detai ...