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之 ...
随机推荐
- 【Linux】实现端口转发的rinetd
Linux下端口转发一般都使用iptables来实现,使用iptables可以很容易将TCP和UDP端口从防火墙转发到内部主机上.但是如果需要将流量从专用地址转发到不在您当前网络上的机器上,可尝试另一 ...
- 攻防世界—pwn—int_overflow
题目分析 checksec检查文件保护机制 ida分析程序 经典整数溢出漏洞示例 整数溢出原理整数分为有符号和无符号两种类型,有符号数以最高位作为其符号位,即正整数最高位为1,负数为0, 无符号数取值 ...
- 关于SET/GET PARAMETER ID的注意事项
通常这两个语法配合 PARAMETER, select-options中的参数 memory id来使用. 如,选择屏幕定义 PARAMETER p1 TYPE c LENGTH 10 MEMORY ...
- 05--Docker对DockerFile解析
一.是什么: 1.1 DockerFile是用来构建Docker镜像的构建文件,是由一系列命令和参数构成的脚本 1.2 构建步骤: 1.2.1 编写Dockerfile文件 1.2.2 docker ...
- Docker 如何动态修改容器端口映射
Docker端口映射往往是Docker Run命令时通过-p将容器内部端口映射到宿主机的指定端口上,一般来说容器的端口所对应的端口是提前确定需要映射的.但是有些情况下不得不需要临时映射端口,例如Doc ...
- Flask之路由系统
路由系统 路由的两种写法 1.第一种方法: def index(): return render_template('index.html') app.add_url_rule('/index', ' ...
- Spring 是如何解决循环依赖的?
前言 相信很多小伙伴在工作中都会遇到循环依赖,不过大多数它是这样显示的: 还会提示这么一句: Requested bean is currently in creation: Is there an ...
- gRPC Motivation and Design Principles | gRPC https://grpc.io/blog/principles/
gRPC Motivation and Design Principles | gRPC https://grpc.io/blog/principles/
- Turbo Boyer-Moore algorithm
MySQL :: MySQL 8.0 Reference Manual :: 8.3.9 Comparison of B-Tree and Hash Indexes https://dev.mysql ...
- get uuid
https://wx2.qq.com/?&lang=zh_CN /** * 启动二维码登录 */ function doQrcodeLogin() { loginFactory.getUUID ...