hdu 5351 规律+大数

题目大意:定义了一种fib字符串,问第n个fib串的前m个字母前后相等串的最大长度,大约就是这样的

其实主要读完题意的时候并没有思路,但是列几个fib字符串就会发现,除了fib1以外,所有串的前面都是一样的,后面的串就只是在前面串的基础上再贴一个串而已,因此很明显,这里的n其实读下来并没有什么用,基本只是用来告诉我们总串长是第1000个fib数列的数,因此要大数,我就试着写了java大数。然后这个结果就直接列一些,打表就会发现规律了```然后就没有然后了。恩,别忘了mod

 1 import java.math.BigInteger;
 2 import java.util.*;
 3 import java.io.*;
 4 public class Main{
 5     static BigInteger fib[] = new BigInteger[1005];
 6     static BigInteger Mod=new BigInteger("258280327");
 7     public static void init(){
 8         fib[1]=new BigInteger("1");
 9         fib[2]=new BigInteger("1");
10         for(int i=3;i<=1000;++i){
11             fib[i]=fib[i-1].add(fib[i-2]);
12         }
13     }
14     public static void main(String[] args){
15         Scanner input = new Scanner(System.in);
16         init();
17         int T=input.nextInt();
18         while(T--!=0){
19             int n=input.nextInt();
20             BigInteger m=input.nextBigInteger();
21             m=m.add(BigInteger.ONE);
22             int i;
23             for(i=1;i<=1000;++i){
24                 int f=m.compareTo(fib[i]);
25                 if(f<0)break;
26             }
27             System.out.println((m.subtract(fib[i-2].add(BigInteger.ONE))).mod(Mod));
28         }
29         input.close();
30     }
31 }

java大数还是非常好的恩```

时间: 2024-12-11 14:08:58

hdu 5351 规律+大数的相关文章

HDU 5351 MZL&#39;s Border(找规律+高精度)

MZL's Border Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 895    Accepted Submission(s): 287 Problem Description As is known to all, MZL is an extraordinarily lovely girl. One day, MZL was p

HDU 5351 MZL&#39;s Border(java 找规律)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5351 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 defin

HDU 5351——MZL&#39;s Border——————【高精度+找规律】

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 pl

HDU 5351 MZL&#39;s Border(规律)

MZL's Border Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 835    Accepted Submission(s): 268 Problem Description As is known to all, MZL is an extraordinarily lovely girl. One day, MZL was p

hdu 5351 MZL&#39;s Border 打表+高精度

MZL's Border Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 462    Accepted Submission(s): 127 Problem Description As is known to all, MZL is an extraordinarily lovely girl. One day, MZL was pl

多校-HDU 5351 MZL&#39;s Border 数学

f[1] = 'b', f[2] = 'a', f[i] = f[i - 1] + f[i - 2] 斐波那契数列的字符串,给你n和m,前m位中,最长的前缀等于后缀的长度是多少.1≤n≤1000, 1≤m≤length(f[n]) 规律题,虽然我不知道为什么. 1 import java.io.*; 2 import java.util.*; 3 import java.math.*; 4 public class Main{ 5 //Scanner cin = Scanner(System.i

多校第六场 HDU 4927 JAVA大数类

题目大意:给定一个长度为n的序列a,每次生成一个新的序列,长度为n-1,新序列b中bi=ai+1?ai,直到序列长度为1.输出最后的数. 思路:这题实在是太晕了,比赛的时候搞了四个小时,从T到WA,唉--对算组合还是不太了解啊,现在对组合算比较什么了-- import java.io.*; import java.math.*; import java.util.*; public class Main { public static void main(String[] args) { Sca

hdu 1042 N!(大数阶乘,转化为100000这样的比较大的进制)

N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 54172    Accepted Submission(s): 15365 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in one

hdu 4927 Java大数

http://acm.hdu.edu.cn/showproblem.php?pid=4927 [解法]:最后的结果是C(n-1,0)*a[n] -C(n-1, 1) * a[n-1] ……C(n-1,n-1)*a[1].符号位一正一负交替. 因为n有3000 之大,算C(n,i) 时要用到大数. 诶  其实早就把公式推出来了,就是坑在Java语言不熟悉,在编译的时候总是出现这个 我们一直以为是语法错误,但是又发现有什么地方写错了,卡了几个小时,人都要抓狂了. 今天拿着后面过的代码跟第一个交的比较