hdu 5459 Jesus Is Here 数学
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数列一样递推
不断归纳就好了……
@)1%KBO0HM418$J94$1R.jpg)
代码:
#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 数学的更多相关文章
- 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的距离是多少? 解题思路: 直觉告诉我 ...
- 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( ...
- hdu 5459 Jesus Is Here (费波纳茨递推)
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others)Total Submission ...
- 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之 ...
- hdu 5459(2015沈阳网赛) Jesus Is Here
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5459 题意 给出一组字符串,每个字符串都是前两个字符串相加而成,求第n个字符串的c的各个坐标的差的和,结果 ...
- J - Jesus Is Here HDU - 5459 (递推)
大意: 定义$f_1="c",f_2="ff",f_n=f_{n-2}+f_{n-1}$, 求所有"cff"的间距和. 记录c的个数, 总长 ...
- 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 ...
- HDU 5810 Balls and Boxes 数学
Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
随机推荐
- ListView中使用type需要注意的东西 java.lang.ArrayIndexOutOfBoundsException: length=2; index=2 addScrapView
ListView中使用type需要注意的东西 在使用ListView时,如果使用了getItemViewType, 记得他的值一定要是从0开始计数的. 且要覆盖getViewTypeCount方法.并 ...
- 函数flst_get_last
flst_node_t中存有12个字节的内容,前6个字节(page:4 boffset:2)表示相对自己前一个node的fil_addr_t信息,后6个字节表示相对自己后1个node的fil_addr ...
- linux 上下文切换带来的影响
1.保存CPU寄存器中的内容 2.CPU高速缓存中的内容失效 3.重新装载页表,用于给线程程安装一个新的虚拟地址空间,页表缓存失效
- [原]Unity3D深入浅出 - 脚本开发基础(Scripts)
常用脚本事件: Update:每帧调用一次 Start:在第一次Update执行前调用 Awake:脚本实例在创建时调用 FixedUpdate:每个固定物理时间间隔调用一次 LateUpdate:每 ...
- NOI2002robot
这题又是纯数论题…… 独立数就是欧拉函数,政客和军人的含义已经说的很清楚了,学者是最多的…… 首先,如果我们知道了政客和军人的答案,那就只要用n的所有因子的欧拉函数值减去这两个值,然后取模就行了. 但 ...
- Socket编程(九)
此为网络编程的一个系列,后续会把内容补上.....
- Rman实现数据库迁移
Rman实现数据库迁移(从库A迁移到库B)环境:服务器A:Oracle10g+AS3服务器B:Oracle10g+AS4准备工作: 1 在数据库B上建立与库A相同的目录结构(若由于磁盘空间等原因可以用 ...
- Spring基础知识及bean的配置
IOC与DI: IOC(inversion of control):其思想是反转资源获取的方向.传统的资源查找方式要求组件向容器发起请求查找资源.作为回应,容器适时的返回资源.而应用了IOC之后,则是 ...
- 《深入Java虚拟机学习笔记》- 第19章 方法的调用与返回
<深入Java虚拟机学习笔记>- 第19章 方法的调用与返回
- 《Python基础教程(第二版)》学习笔记 -> 第四章 字典
字典是Python中唯一内建的映射类型. 字典中的值并没有特殊的顺序,但是都存储在一个特定的键(Key)里.键可以是数字.字符串甚至是元组. 字典的使用 某些情况下,字典比列表更加适用: 表征游戏棋盘 ...