MZL's Border

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 944    Accepted Submission(s): 306

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 like Fibonacci 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 string s 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 that i<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 numbers n 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 that 1≤T≤100, 1≤n≤103, 1≤m≤|fibn|.

 
Input
The first line of the input is a number T, which means the number of test cases.

Then for the following T lines, each has two positive integers n and m, whose meanings are described in the description.

 
Output
The output consists of T lines. Each has one number, meaning fibn's LBorderm modulo 258280327(=2×317+1).
 
Sample Input
2
4 3
5 5
 
Sample Output
1
2
 
题目大意:这个题目定义了一些新概念,而且比较绕,所以题意不是太好理解。给T组测试数据,每组有n,m。表示从fibn这个字符串中截取子串s[1:m]。然后在这个字串中找到最大的i满足s[1:i]=s[m-i+1:m],即公共前后缀。当时理解成了跟n有关系,即s[1:i]=s[n-i+1:n],主要受那个题的描述影响了。
 
解题思路:其实这个题目计算只跟m有关系,因为n只是进行限制了m的大小,跟n没多大关系。我们列出几项会发现,m跟LBorderm的差值是成斐波那契数列的。
 
import java.io.*;
import java.util.*;
import java.math.*;
public class Main{
public static void main(String [] args){
BigInteger one=BigInteger.ONE, zero = BigInteger.ZERO ;
BigInteger fib[] = new BigInteger [1200];
fib[1]=one;
fib[2]=one;
for(int i=3;i<=1005;i++){
fib[i]=fib[i-1].add( fib[i-2] );
}
Scanner cin = new Scanner (System.in);
int t=cin.nextInt();
while(t>0){
t--;
int n= cin.nextInt();
BigInteger m = cin.nextBigInteger();
for(int i=1;i<=1005;i++){
if(fib[i].compareTo(m.add( one ) )==1){
System.out.println( m.subtract(fib[i-2]).mod(BigInteger.valueOf(258280327 )));
break;
}
}
}
}
}

  

 

HDU 5351——MZL's Border——————【高精度+找规律】的更多相关文章

  1. HDU 5351 MZL's Border (规律,大数)

    [HDU 5351 MZL's Border]题意 定义字符串$f_1=b,f_2=a,f_i=f_{i-1}f_{i-2}$. 对$f_n$的长度为$m$的前缀$s$, 求最大的$k$满足$s[1] ...

  2. 多校-HDU 5351 MZL's Border 数学规律

    f[1] = 'b', f[2] = 'a', f[i] = f[i - 1] + f[i - 2] 斐波那契数列的字符串,给你n和m,前m位中,最长的前缀等于后缀的长度是多少.1≤n≤1000, 1 ...

  3. hdu 2865 Polya计数+(矩阵 or 找规律 求C)

    Birthday Toy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  4. 递推+高精度+找规律 UVA 10254 The Priest Mathematician

    题目传送门 /* 题意:汉诺塔问题变形,多了第四个盘子可以放前k个塔,然后n-k个是经典的汉诺塔问题,问最少操作次数 递推+高精度+找规律:f[k]表示前k放在第四个盘子,g[n-k]表示经典三个盘子 ...

  5. bzoj 1002 [FJOI2007]轮状病毒 高精度&&找规律&&基尔霍夫矩阵

    1002: [FJOI2007]轮状病毒 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2234  Solved: 1227[Submit][Statu ...

  6. HDU 4388 Stone Game II 博弈论 找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=4388 http://blog.csdn.net/y1196645376/article/details/5214 ...

  7. HDU 4349 Xiao Ming's Hope 找规律

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4349 Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/ ...

  8. HDU 4731 Minimum palindrome 打表找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=4731 就做了两道...也就这题还能发博客了...虽然也是水题 先暴力DFS打表找规律...发现4个一组循环节.. ...

  9. HDU 4588 Count The Carries(找规律,模拟)

    题目 大意: 求二进制的a加到b的进位数. 思路: 列出前几个2进制,找规律模拟. #include <stdio.h> #include <iostream> #includ ...

随机推荐

  1. nginx 部署 .net core 获取的客户端ip为127.0.0.1

    采用nginx和.net core 部署一套api接口到服务器上,发现获取到的ip地址为127.0.0.1 经过检查发现,需要在nginx配置上以下参数 proxy_set_header Host $ ...

  2. Django之文件下载

    到目前为止,我们的注意力都在HTML网页上,但是实际上,在网站上除了HTML外还有图片,文件,PDF等等. 首先来看下返回一张图片为例,读取本地磁盘上的一张图片并返回到网页上显示. def test1 ...

  3. [翻译]CURAND Libaray--Host API--(2)

    Translated by xingoo 如果有错误请联系:xinghl90@gmail.com 2.3 返回值 所有的CURAND host端的函数返回值都是curandStatus_t.如果调用没 ...

  4. srs录制视频时间戳有点问题

    srs2或者srs3目前最新的版本和之前的版本,使用dvr功能录制flv文件.使用本地播放器,如ffplay.potplayer.vlc.KMP和MPV等,都是正常的播放完整视频.但是使用web fl ...

  5. P4841 城市规划 FFT+生成函数

    \(\color{#0066ff}{ 题目描述 }\) 刚刚解决完电力网络的问题, 阿狸又被领导的任务给难住了. 刚才说过, 阿狸的国家有n个城市, 现在国家需要在某些城市对之间建立一些贸易路线, 使 ...

  6. CF709A Juicer 模拟

    Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put ...

  7. java 的开发工具IDEA使用 中Debug 调试工具使用

    IDEA JetBrains(这个公司的名称翻译过来就是“大脑喷射?”) 公司的宣传语是这么说的:Develop with pleasure!(带着快乐开发!)   话不多说 开始debug   1, ...

  8. 2016"百度之星" - 资格赛(Astar Round1)D

    Problem Description 度熊所居住的 D 国,是一个完全尊重人权的国度.以至于这个国家的所有人命名自己的名字都非常奇怪.一个人的名字由若干个字符组成,同样的,这些字符的全排列的结果中的 ...

  9. linux 中iscsi服务

      ###############第一步: 创建一个2G的分区第二步: yum install targetcli -y 第三步:创建一个2G的分区,并同步  第四步:  执行tagetclils查看 ...

  10. win10下Anaconda3在虚拟环境python_version=3.5.3 中配置pyspark

    1. 序经过了一天的修炼,深深被恶心了,在虚拟环境中配置pyspark花式报错,由于本人实在是不想卸载3.6版的python,所以硬刚了一天,终于摸清了配置方法,并且配置成功,不抱怨了,开讲: 2. ...