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. Windows Phone 获取网络类型(GSM/CDMA/WIFI/Ethernet)

    一.判断是否有网络数据连接: 最基本的网络状态判断,如果没有网络连接,一切操作都进行不下去啦. Microsoft.Phone.Net.NetworkInformation.NetworkInterf ...

  2. 【转】java提高篇(十)-----详解匿名内部类

    原文网址:http://www.cnblogs.com/chenssy/p/3390871.html 在java提高篇-----详解内部类中对匿名内部类做了一个简单的介绍,但是内部类还存在很多其他细节 ...

  3. PostgreSql字符串函数和操作符

    本节描述了用于检查和操作字符串数值的函数和操作符.在这个环境中的字符串包括所有 character, character varying, text 类型的值.除非另外说明,所有下面列出的函数都可以处 ...

  4. Visual Studio中的一些较大的文件的作用

    1.sdf 这些是工程中的中间,用于预编译等作用,最终可执行文件是不需要的,默认情况下,删除后重新编译还会生成.如果不需要,在Visual Studio里进入如下设置: 进入"Tools & ...

  5. ccr1

    Concurrency and Coordination Runtime Jeffrey Richter Code download available at:ConcurrentAffairs200 ...

  6. ChineseCounter.cs 统计中文文本中常用字占比

    http://www.tuicool.com/articles/qmMba2 1 using System; using System.IO; using System.Collections.Gen ...

  7. 《Python基础教程(第二版)》学习笔记 -> 第三章 使用字符串

    本章讲话介绍如何使用字符串格式化其他的值,并简单了解一下利用字符串的分割.联接.搜索等方法能做些什么. 基本字符串操作 所有标准的序列操作(索引.分片.乘法.判断成员资格.求长度.取最大最小值)对字符 ...

  8. 5个最优秀的Java和C#代码转换工具

    http://www.codeceo.com/article/5-java-csharp-convert-tools.html 毋庸置疑,Java是一门最受欢迎而且使用最广泛的编程语言,目前有超过9百 ...

  9. rt-thread博客分享

    对于理解rtos, 国内有一个rt-thread的开源社区,里面讲解了一些rtos的很多概念,方便了理解很多问题点,博客地址如下: http://www.cnblogs.com/King-Gentle ...

  10. POJ 1005 解题报告

    1.题目描述   2.解题思路 好吧,这是个水题,我的目的暂时是把poj第一页刷之,所以水题也写写吧,这个题简单数学常识而已,给定坐标(x,y),易知当圆心为(0,0)时,半圆面积为0.5*PI*(x ...