Jesus Is Here

Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)
Total Submission(s): 346    Accepted Submission(s): 243

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
 题意:s1 = c,s2 = ff,递推,当i>=3,i等于i-2加上i-1构成,即s3 = cff,问第n个字符串中所有c字符的下标差值
第i个字符串的所有c字符的下标差值肯定由i-1的串还有i-2的串的计算过来的,然而怎么计算……需要什么定义什么,让计算机干什么
你想计算下标差值,这么多数,i-1,i-2,定义-数组把所有的下标和存起来,当算i-1和i-2串的差值计算的时候分两步,算i-2串到串末的距离加上i-1串的距离就等于i-1和i-2串差值
 *****************************************************************************************************************************

ans[i]             =               ans[i-1]+ans[i-2]   +                                       (len[i-2]*num[i-2]-sum[i-2])*num[i-1]                  +                     sum[i-1]*num[i-2];

i  字符串中所有c字符差值 = i-1和i-2差值之和,再加上i-1中的c和i-2中的c的差值, (= 所有 i-2 中的c的下标到i-2串末尾的距离   +  i-1串的和*i-2中c的数量

i-2中的c下标到i-2末尾的距离,就等于i-2中c字符 个 总长度减去c字符的下标之和

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<math.h>
#include<algorithm> using namespace std; const int maxn = ; #define mod 530600414
#define INF 0x3f3f3f3f long long num[maxn], sum[maxn], len[maxn], ans[maxn];
// num是该下标表示的字符串中c的个数,sum是所有c下标之和,len是字符串长度,ans是所有下标差值之和
int main()
{
int t, x;
num[] = len[] = sum[] = ;
len[] = ;
sum[] = num[] = ;
for(int i = ; i < maxn; i++)
{
num[i] = (num[i-] + num[i-])%mod;
len[i] = (len[i-] + len[i-])%mod;
sum[i] = ((sum[i-] + sum[i-])%mod + (len[i-]*num[i-])%mod)%mod; //sum表示c下标和,因为i-1串放在了i-2串的后边,所以sum要加上i-1串中的数量*i-2串的长度,就是i串中所有c的下标和
ans[i] = (ans[i-]%mod + ans[i-]%mod + (num[i-]%mod*len[i-]%mod - sum[i-]%mod)%mod*num[i-]%mod+num[i-]%mod*sum[i-]%mod)%mod;
}
scanf("%d", &t);
for(int i = ; i <= t; i++)
{
scanf("%d", &x);
printf("Case #%d: %I64d\n", i, ans[x]);
}
return ;
}

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

    Problem Description I've sent Fang Fang around 201314 text messages in almost 5 years. Why can't she ...

  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. 《Using Python to Access Web Data》 Week3 Networks and Sockets 课堂笔记

    Coursera课程<Using Python to Access Web Data> 密歇根大学 Week3 Networks and Sockets 12.1 Networked Te ...

  2. 搭建 Git 服务器(基于 CentOS 7)

    服务器上的-Git-架设服务器-官网参考 对于规模比较小的团队,可以直接搭建 Git 服务器,逐个收集研发同学的证书配置进来即可.如果团队规模比较大,可以直接采用 GitLab.Drone 等现成的带 ...

  3. c# 动态加载tlb为程序集

    private enum RegKind { RegKind_Default = , RegKind_Register = , RegKind_None = } [DllImport("ol ...

  4. redis集群主从中断,报io过高 不错

    问题原因:1.由于这个集群redis操作非常频繁,1分钟操作数据达到1-2G,所有自动aof非常频繁,主从复制打包rdb也非常频繁,之前配置已经无法满足要求报异常如下6943:M 19 Jul 20: ...

  5. DP---DAG、背包、LIS、LCS

    DP是真的难啊,感觉始终不入门路,还是太弱了┭┮﹏┭┮ DAG上的DP ​ 一般而言,题目中如果存在明显的严格偏序关系,并且求依靠此关系的最大/最小值,那么考虑是求DAG上的最短路或者是最长路.(据说 ...

  6. JAVA调用shell脚本利用ansible修改多节点上的redis参数

    创建hosts文件 创建ansible-playbook执行时所用到的hosts文件,例如 /etc/redis/hosts 利用shell命令根据传入的host名和地址写入hosts文件: #set ...

  7. HTML: 引号不能忽视

    在js中常常生成拼接html,然后放到dom中,但是有些拼接的html标签需要加一些指或者属性,这个时候不能忽略引号 如果data.link_tel有空格,不加单引号导致value的值不完全 str ...

  8. 关于mysql的使用命令(持续更新中...)

    特别提示  本说明中的mysql 是基于windwos平台下的5.5 版本 安装完成后 请到mysql中设置配置文件   链接分享:链接:https://pan.baidu.com/s/1tv4ulZ ...

  9. SpringBoot(六) -- SpringBoot错误处理机制

    一.SpringBoot中的默认的错误处理机制 1.在SpringBootWeb开发中,当我们访问请求出现错误时,会返回一个默认的错误页面: 2.在使用其他客户端访问的时候,则返回一个json数据: ...

  10. Hadoop Map/Reduce

    Hadoop Map/Reduce是一个使用简易的软件框架,基于它写出来的应用程序能够运行在由上千个商用机器组成的大型集群上,并以一种可靠容错的方式并行处理上T级别的数据集.一个Map/Reduce ...