hdu5459 Jesus Is Here(沈阳网赛)

Jesus Is Here

Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others)

Total Submission(s): 257 Accepted Submission(s): 175

Problem 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: 5
Case #2: 16
Case #3: 88
Case #4: 352
Case #5: 318505405
Case #6: 391786781
Case #7: 133875314
Case #8: 83347132
Case #9: 16520782

Source

2015 ACM/ICPC Asia Regional Shenyang Online

题意:求第n项中所有字符‘c‘的坐标差的和。

分析:每一个新的字符串都是由前两个字符串合成的,所以得到这个公式:ans[n]=ans[n-1]+ans[n-2]+X(X表示两个字符串连接后增加的值);假设第n-2项中字符‘c‘的个数为c1,字符‘c‘坐标之和为s1,字符总个数为n1,第n-1项中字符‘c‘的个数为c2,字符‘c‘坐标之和为s2,字符总个数为n2;

1、对于n-1这个串里的每个’c‘所增加的值为n-2中’c‘的反向坐标(就是串长 - 坐标,记为cc ),即c2*(c1*n1-s1);(把c1*n1-s1 拆分成一个一个的c相加,就相当于c1个cc相加)

2、对于n-2这个串里的每个’c‘所增加的值就为n-1中’c‘的坐标,即c1*s2。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 530600414;
#define ll long long
#define CL(a) memset(a,0,sizeof(a))

ll ans[300000];//答案
ll c[300000];//c的个数
ll s[300000];//c的坐标和
ll d[300000];//长度

int main()
{
    ans[1]=0; ans[2]=0; ans[3]=1;
    ans[4]=1; c[4]=1; s[4]=3; d[4]=3;
    ans[5]=5; c[5]=2; s[5]=7; d[5]=5;
    ans[6]=16; c[6]=3; s[6]=20; d[6]=8;
    for(int i=7; i<=201314; i++)
    {
        ans[i]=(ans[i-1]+ans[i-2]+(((c[i-2]*d[i-1]-s[i-2])%MOD)*c[i-1])%MOD+(c[i-2]*s[i-1])%MOD)%MOD;
        c[i]=(c[i-1]+c[i-2])%MOD;
        s[i]=(s[i-1]+s[i-2]+c[i-1]*d[i-1])%MOD;//第(i-1)个字符串里的c坐标都要加上第(i-2)个串的长度
        d[i]=(d[i-1]+d[i-2])%MOD;
    }

    int T,n;
    scanf ("%d",&T);
    for(int cas=1; cas<=T; cas++)
    {
        scanf ("%d",&n);
        printf ("Case #%d: ",cas);
        printf ("%lld\n",ans[n]);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-01 22:36:10

hdu5459 Jesus Is Here(沈阳网赛)的相关文章

hdu 5459 Jesus Is Here 沈阳网赛

按照这个规律找出来的不断取模之下会得负数.需要(ans+mod)%mod,化为正数. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define ll __int64 const ll mod=530600414; const int maxn=201399; ll w[maxn],ans[maxn],num[maxn],len[maxn]; void init(

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: 88 Case #4: 352 Case #5: 318505405 Case #6: 391786781 Case #7: 133875314 Case #8: 83347132 Case #9: 16520782 题目要求当前字符串序列中某项里cff前缀两两间差值的和. 假设已经纪录了cff前缀的

2015年沈阳网赛 Jesus Is Here(DP中的计数问题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5459 题目描述:给定一个递推得来的字符串,问字符串中不同cff之间的距离之和, 递推规则: s1=c; s2=ff sn=s[n-2]s[n-1]; 可以观察到任意一个c都被两个ff包含,所以相当于求任意两个c之间的距离之和. 设s[n-2]为p1,p2,p3,,,,p[x],s[n-1]为q1,q2,q3,,,,q[y]; X和y分别为字符串中c的个数:设cnt_c[i]为第i个字符串中c的个数,

hdu 5459(2015沈阳网赛) Jesus Is Here

题目;http://acm.hdu.edu.cn/showproblem.php?pid=5459 题意 给出一组字符串,每个字符串都是前两个字符串相加而成,求第n个字符串的c的各个坐标的差的和,结果要模530600414. 很容易看出字符串的长度及c的个数都是由斐波那契数列构成的,得到最后结果是ans[i]=ans[i-1]+ans[i-2]+x,要求的就是x 假设第n项中字符'c'的个数为cn,字符'c'坐标之和为sn,字符串长度为ln 当形成第i个字符串的时候对于第i-1个字符串来说,这个

【转】HDU 6194 string string string (2017沈阳网赛-后缀数组)

转自:http://blog.csdn.net/aozil_yang/article/details/77929216 题意: 告诉你一个字符串和k , 求这个字符串中有多少不同的子串恰好出现了k 次. 思路: 后缀数组. 我们先考虑至少出现k 次的子串, 所以我们枚举排好序的后缀i (sa[i]) . k段k 段的枚举. 假设当前枚举的是 sa[i]~sa[i + k -1] 那么假设这一段的最长公共前缀  是L 的话. 那么就有L 个不同的子串至少出现了k次. 我们要减去至少出现k + 1次

hdu 5455 (2015沈阳网赛 简单题) Fang Fang

题目;http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意就是找出所给字符串有多少个满足题目所给条件的子串,重复的也算,坑点是如果有c,f以外的字符也是不满足条件的,还有我被坑了的地方就是当输入很多f的时候,我尽然脑抽的 认为这是不满足条件的,注意这两点就行了,直接暴力 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 int main() 5 { 6 int

hdu5461 Largest Point(沈阳网赛)

Largest Point Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 536 Accepted Submission(s): 230 Problem Description Given the sequence A with n integers t1,t2,?,tn. Given the integral coefficients a

2015长春、沈阳网络赛总结

我所说的总结并不是谈什么题目解法之类的东西 这些东西网上有很多题解 说说这两场网赛吧! 这两场我的状态还行,只是xiaodong还没有找到状态,长春赛lucas+中国剩余定理他硬是打了一整场,还是没打出来,版题没打出来确实不该 wzb状态一般,不过看题的能力依然那么厉害 长春赛中,很遗憾的只出了5道题,按当时过题数目,应该是7道德,可是小东的lucas那题没打出来,而我打得后缀数组那题,当顺时针的时候不用看是否是下标最前面的,但是反过来就需要看了,当时想当然的认为不用,交了4发,一直wa到比赛结

ACM学习历程—HDU 5023 A Corrupt Mayor&#39;s Performance Art(广州赛区网赛)(线段树)

Problem Description Corrupt governors always find ways to get dirty money. Paint something, then sell the worthless painting at a high price to someone who wants to bribe him/her on an auction, this seemed a safe way for mayor X to make money. Becaus