hdu 5459 Jesus Is Here 数学

时间:2023-03-09 08:53:58
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数列一样递推

不断归纳就好了……

hdu 5459 Jesus Is Here 数学

代码:

#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]);
}
}