hdu5459 Jesus Is Here
``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.
indicating there are T test
cases.
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.
5
6
7
8
113
1205
199312
199401
201314
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的更多相关文章
- 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的距离是多少? 解题思路: 直觉告诉我 ...
- Jesus Is Here
Jesus Is Here Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others)To ...
- 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之 ...
随机推荐
- 【Oracle】dump函数用法
Oracle dump函数的用法 一.函数标准格式: DUMP(expr[,return_fmt[,start_position][,length]]) 基本参数时4个,最少可以填的参数是0个.当完全 ...
- golang语言初体验
Go(又称 Golang)是 Google 的 Robert Griesemer,Rob Pike 及 Ken Thompson 开发的一种静态强类型.编译型语言.Go 语言语法与 C 相近,但功能上 ...
- H3C、Huawei、Cisco网络设备AAA TACACS认证配置
TACACS技术白皮书 摘要:TACACS是实现AAA功能的一种安全协议,主要是通过TACACS客户端与TACACS服务器通信来实现多种用户的AAA功能. HWTACACS采用TCP协议承载报文,TC ...
- ubuntu安装mysql5.6
安装mysql5.6在ubuntu上安装mysql5.6的版本 1.添加mysql5.6的源 sudo apt-get install software-properties-common sudo ...
- yoctoproject 地址
第一次接触到yoctop. 在这里分享yoctoproject地址 https://www.yoctoproject.org/docs/2.3.3/ref-manual/ref-manual.html ...
- redis 主从复制 和集群
redis集群最少三个节点 之间相互通信ping-pong 投票选举机制 主从复制 的话 最少六个节点 ,主三从三
- css选择器有哪些,选择器的权重的优先级
选择器类型 1.ID #id 2.class .class 3.标签 p 4.通用 * 5.属性 [type="text"] 6.伪类 :hover 7.伪元素 ::first-l ...
- worker 启动时向 etcd 注册自己的信息,并设置一个带 TTL 的租约,每隔一段时间更新这个 TTL,如果该 worker 挂掉了,这个 TTL 就会 expire 并删除相应的 key。
1.通过etcd中的选主机制,我们实现了服务的高可用.同时利用systemd对etcd本身进行了保活,只要etcd服务所在的机器没有宕机,进程就具备了容灾性. https://mp.weixin.qq ...
- Java关键字及作用解释
访问控制 1) private 私有的 private 关键字是访问控制修饰符,可以应用于类.方法或字段(在类中声明的变量). 只能在声明 private(内部)类.方法或字段的类中引用这些类.方法或 ...
- Golang之如何(优雅的)比较两个未知结构的json
这是之前遇到的一道面试题,后来也确实在工作中实际遇到了.于是记录一下,如何(优雅的)比较两个未知结构的json. 假设,现在有两个简单的json文件. { "id":1, &quo ...