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

这题主要是推公式,记c[i]为c字符的个数,s[i]为c字符的坐标和,n[i]为所有字符的总个数,f[i]表示求的距离差。

那么f[i]=(c[i-2]*n[i-2]-s[i-2])*c[i-1]+c[i-2]*s[i-1];其中c[i-2]*n[i-2]-s[i-2]为所有c前半部分到合并中间的距离和。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
#define inf 0x7fffffff
#define mod 530600414
#define maxn 201316
ll f[maxn],c[maxn],s[maxn],n[maxn]; void init()
{
int i,j;
c[3]=1;s[3]=1;n[3]=3;f[3]=0;
c[4]=1;s[4]=3;n[4]=5;f[4]=0;
for(i=5;i<=201314;i++){
f[i]=(f[i-1]+f[i-2]+ ( (c[i-2]*n[i-2]-s[i-2])%mod )*c[i-1]%mod+c[i-2]*s[i-1]%mod )%mod;
n[i]=(n[i-1]+n[i-2])%mod;
c[i]=(c[i-1]+c[i-2])%mod;
s[i]=( (s[i-2]+ s[i-1])%mod+(n[i-2]*c[i-1])%mod )%mod;
}
} int main()
{
int m,i,j,T,num1=0,d;
scanf("%d",&T);
init();
while(T--)
{
scanf("%d",&d);
num1++;
printf("Case #%d: %lld\n",num1,f[d]);
}
return 0;
}

hdu5459 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. Jesus Is Here

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

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

    脚手架工具 脚手架工具概要(前端工程化的发起者) 脚手架的本质作用:创建项目基础架构.提供项目规范和约定 相同的组织结构 相同的开发规范 相同的模块依赖 相同的工具配置 相同的基础代码 举例:IDE创 ...

  2. 【Linux】linux的所有文件分类解析

    今天看书的时候,无意间看到/dev/文件夹,以前没注意,今天去看了下发现,很多文件的开头文件属性都是一些不怎么见到的 常见的是   -     这个是代表文件,可以vim编辑的 d     这个是代表 ...

  3. openshift 3.11安装部署

    openshift 3.11 安装部署 openshift安装部署 1 环境准备(所有节点) openshift 版本 v3.11 1.1 机器环境 ip cpu mem hostname OSsys ...

  4. 【Python】中国有哪些同名的省市县?

    这道题适合写个脚本来解. 首先从百度地图API下载一份行政区划数据. 开发资源 | 百度地图API SDK 然后做一个简单的数据统计就可以啦~ 行政区划同一级同名的: import pandas as ...

  5. 图像Demosaic算法及其matlab实现

    由于成本和面积等因素的限定,CMOS/CCD在成像时,感光面阵列前通常会有CFA(color filter array),如下图所示,CFA过滤不同频段的光,因此,Sensor的输出的RAW数据信号包 ...

  6. Databricks 第10篇:Job

    Job是立即运行或按计划运行notebook或JAR的一种方法,运行notebook的另一种方法是在Notebook UI中以交互方式运行. 一,使用UI来创建Job 点击"Jobs&quo ...

  7. python3多进程 进程池 协程并发

    一.进程           我们电脑的应用程序,都是进程,进程是资源分配的单位.进程切换需要的资源最大,效率低.         进程之间相互独立         cpu密集的时候适合用多进程 #多 ...

  8. Win2008 server R2重置登录密码Administrator

    1.PE方式修改密码 背景:https://www.cnblogs.com/Crazy-Liu/p/11245730.html 上述连接中的有AD域的机器系统使用哑巴式老毛桃等启动PE出现以下: 原因 ...

  9. JAVA不可不知的强软弱虚四种引用

    一个变量指向new对象,就是引用,在java中有四种引用,分别是强软弱虚,常见的Object o = new Object(),就是强引用,垃圾回收的时候,强引用不会被回收.   公用类: publi ...

  10. cpp异常机制思考

    https://www.cnblogs.com/qq329914874/p/6734701.html