HDOJ 5351 MZL's Border 找规律
来源:互联网 发布:无锡作协网络分会成立 编辑:程序博客网 时间:2024/06/06 18:35
打出前i个串的kmp的fail指针:
p: ab0 0 0 p: aba0 0 0 1 p: abaab0 0 0 1 1 2 p: abaababa0 0 0 1 1 2 3 2 3 p: abaababaabaab0 0 0 1 1 2 3 2 3 4 5 6 4 5 p: abaababaabaababaababa0 0 0 1 1 2 3 2 3 4 5 6 4 5 6 7 8 9 10 11 7 8 p: abaababaabaababaababaabaababaabaab0 0 0 1 1 2 3 2 3 4 5 6 4 5 6 7 8 9 10 11 7 8 9 10 11 12 13 14 15 16 17 18 19 12 13 p: abaababaabaababaababaabaababaabaababaababaabaababaababa0 0 0 1 1 2 3 2 3 4 5 6 4 5 6 7 8 9 10 11 7 8 9 10 11 12 13 14 15 16 17 18 19 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 20 21 p: abaababaabaababaababaabaababaabaababaababaabaababaababaabaababaabaababaababaabaababaabaab0 0 0 1 1 2 3 2 3 4 5 6 4 5 6 7 8 9 10 11 7 8 9 10 11 12 13 14 15 16 17 18 19 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 33 34
然后就发现规律了.....
MZL's Border
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 853 Accepted Submission(s): 275
Problem Description
As is known to all, MZL is an extraordinarily lovely girl. One day, MZL was playing with her favorite data structure, strings.
MZL is really likeFibonacci Sequence , so she defines Fibonacci Strings in the similar way. The definition of Fibonacci Strings is given below.
1)fib1=b
2)fib2=a
3)fibi=fibi−1fibi−2, i>2
For instance,fib3=ab, fib4=aba, fib5=abaab .
Assume that a strings whose length is n is s1s2s3...sn . Then sisi+1si+2si+3...sj is called as a substring of s , which is written as s[i:j] .
Assume thati<n . If s[1:i]=s[n−i+1:n] , then s[1:i] is called as a Border of s . In Borders of s , the longest Border is called as s ' LBorder . Moreover, s[1:i] 's LBorder is called as LBorderi .
Now you are given 2 numbersn and m . MZL wonders what LBorderm of fibn is. For the number can be very big, you should just output the number modulo 258280327(=2×317+1) .
Note that1≤T≤100, 1≤n≤103, 1≤m≤|fibn| .
MZL is really like
1)
2)
3)
For instance,
Assume that a string
Assume that
Now you are given 2 numbers
Note that
Input
The first line of the input is a number T , which means the number of test cases.
Then for the followingT lines, each has two positive integers n and m , whose meanings are described in the description.
Then for the following
Output
The output consists of T lines. Each has one number, meaning fibn 's LBorderm modulo 258280327(=2×317+1) .
Sample Input
24 35 5
Sample Output
12
Source
2015 Multi-University Training Contest 5
import java.util.*;import java.math.*;public class Main {final BigInteger mod = BigInteger.valueOf(258280327);BigInteger fib[] = new BigInteger[1100];BigInteger sum[] = new BigInteger[1100];BigInteger all[] = new BigInteger[1100];void init() {fib[1]=BigInteger.ONE; fib[2]=BigInteger.ONE;sum[1]=BigInteger.ZERO; sum[2]=BigInteger.ONE;for(int i=3;i<=1010;i++) {fib[i]=fib[i-1].add(fib[i-2]);sum[i]=sum[i-1].add(fib[i]);}all[1]=BigInteger.valueOf(2);for(int i=2;i<=1010;i++) {all[i]=all[i-1].add(fib[i].multiply(BigInteger.valueOf(2)));}}void solve(BigInteger x) {if(x.compareTo(BigInteger.valueOf(2))<1) {System.out.println(0);return ;}for(int i=1;i<=1000;i++) {int k=x.compareTo(all[i]);if(k==1) continue;else if(k==0) {System.out.println(sum[i].mod(mod));return ;}else{BigInteger y = x.subtract(all[i-1]);if(y.compareTo(fib[i])>0) {y=y.subtract(fib[i]);}System.out.println(y.add(sum[i-1]).mod(mod));return ;}}}Main(){init();Scanner in = new Scanner(System.in);int T_T;T_T=in.nextInt();while(T_T-->0) {int n=in.nextInt();BigInteger m = in.nextBigInteger();solve(m);}}public static void main(String[] args) {new Main();}}
1 0
- HDOJ 5351 MZL's Border 找规律
- HDU 5351 MZL's Border(找规律)
- HDU 5351 MZL's Border(java 找规律)
- HDU 5351 MZL's Border(找规律+高精度)
- Hdu 5351 MZL's Border (找规律+Java高精度)
- HDU 5351 MZL's Border(大数+规律)
- HDU 5351 MZL's Border(规律)
- 多校-HDU 5351 MZL's Border 数学规律
- HDU 5351 MZL's Border(大数 + 找规律)——2015 Multi-University Training Contest 5
- hdu5351(2015多校5)--MZL's Border(打表,,找规律)
- HDU 5351 MZL's Border
- HDU 5351 MZL's Border
- HDU 5351 MZL's Border
- [hdu 5351] MZL's Border
- HDU 5351 MZL's Border(2015多校第五场第9题) 写长串找规律
- hdu 5351 MZL's Border (大数)
- 109.hdu--5351--MZL's Border
- HDU5351 MZL's Border
- Python 之 向上取整、向下取整以及四舍五入函数
- git学习之旅(二)——多人合作
- 保护模式下的内存访问
- 数据分析变革 大数据时代精准决策之道——互动出版网
- 大数模小数
- HDOJ 5351 MZL's Border 找规律
- USACO 2.2.1 Preface Numbering
- iPhone--什么是解锁
- StretchDIBits函数隐含的图像坐标系设置
- Algorithms(一)---最大子数组和问题
- pl/sql存储过程中游标嵌套的实现方法
- 19个实用的Android开发工具
- C# 字符串处理
- bootstrap(下拉菜单与滚动监听)