Jesus Is Here
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
``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.
Following T lines, each line contain an integer n (3≤n≤201314), as the identifier of message.
Each line contains an integer equaling to:
where sn as a string corresponding to the n-th message.
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的更多相关文章
- hdu 5459 Jesus Is Here (费波纳茨递推)
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others)Total Submission ...
- hdu 5459 Jesus Is Here 数学
Jesus Is Here Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- 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的距离是多少? 解题思路: 直觉告诉我 ...
- hdu5459 Jesus Is Here
Problem Description I've sent Fang Fang around 201314 text messages in almost 5 years. Why can't she ...
- 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( ...
- J - Jesus Is Here HDU - 5459 (递推)
大意: 定义$f_1="c",f_2="ff",f_n=f_{n-2}+f_{n-1}$, 求所有"cff"的间距和. 记录c的个数, 总长 ...
- hdu 5459(2015沈阳网赛) Jesus Is Here
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5459 题意 给出一组字符串,每个字符串都是前两个字符串相加而成,求第n个字符串的c的各个坐标的差的和,结果 ...
- 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 ...
- HDU 5459 Jesus Is Here (递推,组合数学)
有点麻烦的递推,递推的原则:向小的问题方向分解,注意边界. 字符串的递推式为 定义f为Si中的总方案数 首先可以得到 fi=fi-1+fi-2+组合(si-2,si-1) 然后考虑Si-2和Si-1之 ...
随机推荐
- 模拟鼠标向下滚动 http://bbs.2ccc.com/topic.asp?topicid=461769
我想模拟鼠标滚轮,下面的代码能向上滚动,怎么样下向滚动啊 mouse_event( MOUSEEVENTF_WHEEL,0,0,WHEEL_DELTA,0); 我把参数设置为mouse_event( ...
- 07 oracle 非归档模式 inactive/active/current redo log损坏的恢复
在非归档模式下缺失Redo Log后的恢复 将之前的归档模式修改为非归档 SQL> shutdown immediate; SQL> startup mount SQL> alter ...
- Android 静态广播和动态广播接收顺序
Android广播有两个很重要的要素: 1 广播 - 用于发送广播 有序广播 - 被广播接收器接收后,可被终止,无法往下继续传达. 典型代表:短信广播 普通广播 - 发送至每一 ...
- 使用 Spring HATEOAS 开发 REST 服务
使用 Spring HATEOAS 开发 REST 服务 学习博客:https://www.ibm.com/developerworks/cn/java/j-lo-SpringHATEOAS/ htt ...
- python基础-6.2正则表达式,计算器练习
content = "1-2*((60-30+(1-40/5*5+3-2*5/3)*(9-2*5/3+7/3*99/4*2998+10*568/14))-(-4*3)/(16-3*2))&q ...
- CDH平台搭建解决离线安装依赖包的方法
背景介绍: 1CDH开发平台在搭建的过程中,会遇到各种各样的问题,其中的各种依赖就是一个很让人头痛的问题.如果安装脚本文件出现了这种问题,那么就可以把以下的这种方法加入shell中,但是不要用yum来 ...
- Maven 标准项目结构
项目结构 src main java 源文件 resources 资源文件 filters 资源过滤文件 config 配置文件 scripts 脚本文件 webap ...
- C++ 中赋值运算符重载以及深拷贝浅拷贝解析
转载自:http://blog.csdn.net/business122/article/details/21242857 关键词:构造函数,浅拷贝,深拷贝,堆栈(stack),堆heap,赋值运算符 ...
- C++ 14 新特性总结
转载自: http://www.codeceo.com/article/cpp-14-new-features.html C++14 这一继C++11 之后的新的 C++ 标准已经被正式批准,正在向 ...
- 纯css实现网上商城左侧垂直商品分类菜单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...