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. awk单引号处理

    awk中使用单引号,常规字符串,'\''即可,但如果像下面在$4变量用单引号,则还需要加上双引号才行. cat 2.txt | awk '{ print $1, $2, $3, "'\''& ...

  2. Java选择排序算法

    package com.jckb; /**选择排序 * * @author gx *算法原理: *第一个数和后面每个数进行比较,如果大于后面的数就进行位置交换, *第一次比较结束后得到了最小值 */ ...

  3. webpack.config.js====插件html-webpack-plugin

    1. 安装 cnpm install html-webpack-plugin --save-dev 2. webpack.config.js中使用 const htmlWebpackPlugin = ...

  4. JavaWeb_05_xml相关&dtd快速入门

    学东西怎么学,是什么,能做什么,怎么去做!! 1.xml的简介 1.eXtensible Markup Language:可扩展标记型语言 标记型语言:html是标记型语言 也是使用标签来操作 可扩展 ...

  5. Map-HashMap-LinkedHashMap-Map.Entry-Collections-可变参数

    一.Map 接口(java.util) 定义:public interface Map<K,V> 介绍:     (1)Map是一个接口,含有两个泛型,创建子类对象的时候,需要传递两个泛型 ...

  6. static 关键字用法

    static a=0; 就是把a初始化为0:初始值为0而已 即使a是局部变量,每次进入此变量所在的函数,a值还是保持上次赋值: 在中断里建议在局部变量前加上static,以确保此变量值的寿命

  7. HTTP错误码汇总(转)

    响应码由三位十进制数字组成,它们出现在由HTTP服务器发送的响应的第一行.响应码分五种类型,由它们的第一位数字表示:1.1xx:信息,请求收到,继续处理2.2xx:成功,行为被成功地接受.理解和采纳3 ...

  8. AutoHotKey设置ide的光标功能键

    CapsLock:: SetCapsLockState,off ;锁定为小写 CapsLock & d:: flag_C=1 ;小写d代替control键,实现跨词移动CapsLock &am ...

  9. UVALive 3523 Knights of the Round Table 圆桌骑士 (无向图点双连通分量)

    由于互相憎恨的骑士不能相邻,把可以相邻的骑士连上无向边,会议要求是奇数,问题就是求不在任意一个简单奇圈上的结点个数. 如果不是二分图,一定存在一个奇圈,同一个双连通分量中其它点一定可以加入奇圈.很明显 ...

  10. CF Gym 100637G \#TheDress (水)

    题解:读懂题意按照题意模拟... 熟悉了一个库函数,strstr,memcpy #include<cstdio> #include<cstring> int main() { ...