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 ...
随机推荐
- Android开发UI之开源项目第一篇——个性化控件(View)篇
原文:http://blog.csdn.net/java886o/article/details/24355907 本文为那些不错的Android开源项目第一篇——个性化控件(View)篇,主要介绍A ...
- HTML5学习(十一)---服务器发送事件
参考教程:http://www.w3school.com.cn/html5/html_5_serversentevents.asp HTML5 服务器发送事件(server-sent event)允许 ...
- 移动端调试 weinre
weinre 是基于 Node 的工具,因此使用如下命令安装 weinre $ npm install -g weinre 用上面的命令将 weinre 安装到全局,然后就可以使用 weinre的命令 ...
- 【JAVA】别特注意,POI中getLastRowNum() 和getLastCellNum()的区别
hssfSheet.getLastRowNum();.行标,比行数小1 hssfSheet.getRow(k).getLastCellNum();//获取列数,比最后一列列标大1 行标.列标都以0开始 ...
- bzoj1532
就题目而言,这道题是裸的二分+最大流 但是这样是TLE的,我们考虑优化 1. 我们可以先贪心,这样二分的上界就可以缩小了 2. 最大流我们可以不急着跑增广路,我们可以先贪心一个流然后再跑增广路 但是我 ...
- UVa 221 (STL 离散化) Urban Elevations
题意: 作图为n个建筑物的俯视图,右图为从南向北看的正视图,按从左往右的顺序输出可见建筑物的标号. 分析: 题中已经说了,要么x相同,要么x相差足够大,不会出现精度问题. 给这n个建筑物从左往右排序, ...
- Cacti 'graph_xport.php' SQL注入漏洞
漏洞版本: Cacti < 0.8.8b 漏洞描述: Bugtraq ID:66555 Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具. Cact ...
- 干货分享:让你分分钟学会 javascript 闭包
闭包,是 javascript 中重要的一个概念,对于初学者来讲,闭包是一个特别抽象的概念,特别是ECMA规范给的定义,如果没有实战经验,你很难从定义去理解它.因此,本文不会对闭包的概念进行大篇幅描述 ...
- HTTP编程(六)
此为网络编程的一个系列,后续会把内容补上.....
- 如何从Linux源码获知版本信息
/*************************************************************************** * 如何从Linux源码获知版本信息 * 声明 ...