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个字符串来说,这个串里的每个’c‘所增加的值为i-2中’c‘的反向坐标(就是串长 - 坐标,记为cc ),即c2*(c1*l1-s1);(把c1*n1-s1 拆分成一个一个的c相加,就相当于c1个cc相加)

对于第i-2个字符串来说就是每个’c‘所增加的值就为i-1中’c‘的坐标,即c1*s2

两者之和就是x

这题当输入3或者4的时候都输出0或者都输出1的时候都可以,就是说后端数据中没有3和4折两组

 1 #include<cstdio>
 2 using namespace std;
 3 typedef long long ll;
 4 int mod=530600414;
 5 ll ans[201315],c[201315],s[201315],l[201315];
 6 int main()
 7 {
 8     int t,n,i,sum;
 9     ans[3]=0;ans[4]=0;
10     c[3]=1;s[3]=1;l[3]=3;
11     c[4]=1;s[4]=3;l[4]=5;
12     for (i=5;i<=201314;i++)
13     {
14         ans[i]=(((ans[i-1]+ans[i-2])%mod+c[i-2]*s[i-1])%mod+((c[i-2]*l[i-2]-s[i-2])%mod*c[i-1])%mod)%mod;
15         l[i]=(l[i-1]+l[i-2])%mod;
16         c[i]=(c[i-1]+c[i-2])%mod;
17         s[i]=((s[i-1]+s[i-2])%mod+l[i-2]*c[i-1])%mod;
18     }
19     ans[3]=1,ans[4]=1;//所以这一步要不要无所谓
20     while (~scanf("%d",&t))
21     {
22         sum=1;
23         while (t--)
24         {
25             scanf("%d",&n);
26             printf("Case #%d: %I64d\n",sum++,ans[n]);
27         }
28     }
29     return 0;
30 }
时间: 2024-08-29 14:15:35

hdu 5459(2015沈阳网赛) Jesus Is Here的相关文章

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

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 5475(2015上海网赛) An easy problem

题目;http://acm.hdu.edu.cn/showproblem.php?pid=5475 题意就是给X赋初值1,然后给Q个操作,每个操作对应一个整数M:如果操作是1则将X乘以对应的M,如果是2则除以第M次操作对应的M',求最后X的值对给定值取摸的结果, 直接暴力会爆long long,用数组存每一步的话 会超时,所以用线段树优化进行区间更新 1 #include<cstdio> 2 using namespace std; 3 typedef long long ll; 4 stru

hdu 5443 (2015长春网赛G题 求区间最值)

求区间最值,数据范围也很小,因为只会线段树,所以套了线段树模板=.= Sample Input3110011 151 2 3 4 551 21 32 43 43 531 999999 141 11 22 33 3 Sample Output1002344519999999999991 1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm>

2015沈阳网络赛1003 Minimum Cut 树链剖分 数组维护前缀和进行区间增减

2015沈阳网络赛1003  Minimum Cut   树链剖分 数组维护前缀和进行区间增减 Minimum Cut Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Given a simple unweighted graph G 

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(

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

hdu 5441 Travel (2015长春网赛)

http://acm.hdu.edu.cn/showproblem.php?pid=5441 题目大意是给一个n个城市(点)m条路线(边)的双向的路线图,每条路线有时间值(带权图),然后q个询问,每个询问一个时间值 求不大于这个时间的可以连通的城市有多少种连法 比如样例中第一个询问6000,不大于6000时间值的连通城市有3,5.所以有3-->5,5-->3两种 第二个询问10000,符合条件的连通的城市有2,3,5,所以有2-->3,3-->2,2-->5,5-->2