题目名称:MZL's Border

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5351

题意:给出fib 1 = b,fib2 = a ; fib i =
fib i-1 fib i-2 ,这个递推关系,比如。fib 3 = ab,fib 4 =
aba 然后说了一大堆东西,事实上就是要我们求前m个字母中满足 i < n , s [ 1 : i ]=s [ n - i - 1 : n ] 。( s [ 1 : i ]表示串 s 的子串s1s2s3s4s4...si ) 的 i 的最大值

思路:看到这道题是不是自然而然的就想到了KMP。对,一開始我用KMP准备把最大的那个串给保存在next数组里面,因为该串是斐波拉切增长的,,所以数组爆了,然后这道题每一次是把上一个串加到后面,所以想到了打表找规律。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  这样是不是规律就出来了啊==。然后还得用高精度==。因为JAVA 的高精度比較easy写,以下给出JAVA的代码

代码例如以下:

import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner in=new Scanner(System.in);
int t;
while(in.hasNext())
{
t=in.nextInt();
for(int pp=0;pp<t;pp++)
{
BigInteger n,m,sum=BigInteger.ONE;
BigInteger cnt=BigInteger.ZERO;
BigInteger ss[] = new BigInteger[3];
ss[1]=BigInteger.ONE;ss[0]=BigInteger.ONE;
cnt=new BigInteger("4");
n = in.nextBigInteger();
m = in.nextBigInteger();
BigInteger two = new BigInteger("2");
if(new BigInteger("3").compareTo(m)==1) //m<3
System.out.println("0");
else{
for(;;)
{
ss[2]=ss[1].add(ss[0]);
if(( (cnt.add(ss[2].add(ss[2]))).compareTo(m) ) ==1) //cnt+ss[2]*2>m
break;
cnt=cnt.add(ss[2].add(ss[2])); //cnt=cnt+ss[2]*2
sum=(sum.add(ss[2])).mod(new BigInteger("258280327")); //sum=(sum+ss[2])%258280327
ss[0]=ss[1];
ss[1]=ss[2];
}
if(m.subtract(cnt).compareTo(ss[2])==1)
System.out.println( (m.subtract(ss[2]).add(sum).subtract(cnt)).mod(new BigInteger("258280327")));
else
System.out.println( (m.add(sum).subtract(cnt) ) .mod(new BigInteger("258280327")));
// if(m-cnt>ss[2])
// cout<<(m-ss[2]+sum-cnt)%258280327<<endl;
// else
// cout<<(m+sum-cnt)%258280327<<endl;
// }
}
}
}
}
}

hdu5351的更多相关文章

  1. hdu5351 MZL's Border(规律题,java)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud MZL's Border Time Limit: 2000/1000 MS (Ja ...

  2. HDU-5351

    MZL's Border Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  3. [hdu5351]找规律,大整数模板

    题意:f(1)="a",f(2)="b",f(i)=f(i-1)+f(i-2),"+"表示连接符.给定n,m,求f(n)的前m个字符的“ne ...

随机推荐

  1. HDU 4341

    分组背包而已.注意的是,每个时间T,要把一组的全加进去比较一次. #include <iostream> #include <cstdio> #include <cstr ...

  2. exFAT格式

    买了一个64GB的T卡,发如今Windows XP上格式化."文件系统"仅仅有exFAT选项. 用这个exFAT格式化还失败了. 给XP打上KB955704补丁,能够用exFAT格 ...

  3. SGU 531 - Bonnie and Clyde 预处理+二分

    Bonnie and Clyde Description Bonnie and Clyde are into robbing banks. This time their target is a to ...

  4. 杂项-分布式:Hadoop

    ylbtech-杂项-分布式:Hadoop Hadoop是一个由Apache基金会所开发的分布式系统基础架构. 用户可以在不了解分布式底层细节的情况下,开发分布式程序.充分利用集群的威力进行高速运算和 ...

  5. 1到32 数字正则 还有IP的

    正则是按位解析匹配的,所以[1-32]是不行的. 解析: 1.1-32,包含1位数(1-9)和2位数(10-32) 2.10-32必须切割,10-19和20-29形式一样,得到[12][0-9],30 ...

  6. 如何巧妙使用ZBrush中的Image Plane插件

    ZBrush®插件Image Plane提供了一种简单的方法加载图像到ZBrush中,以在添加纹理过程中进行使用,比如使用ZProject笔刷多边形着色,以及利用参考图建模等. ZBrush 中文版下 ...

  7. Codeforces Round #493 (Div. 2) B. Cutting 前缀和优化_动归水题

    不解释,题目过水 Code: #include<cstdio> #include<cmath> #include<algorithm> using namespac ...

  8. Pyhton学习——Day50

    #HTTP协议# 又是转载:http://www.cnblogs.com/yuanchenqi/articles/6000358.html# 一 HTTP概述# HTTP(hypertext tran ...

  9. 粘包解决高端_Server

    from socket import * #导入套接字模块的所有命令import subprocess #导入subprocess模块,用于执行命令行import struct #导入struck模块 ...

  10. systemd bug: bz1437114 core:execute: fix fork() fail handling in exec_spawn()

    问题现象 大量僵尸进程 root 32278 0.0 0.0 0 0 ? Z 05:39 0:00 [runuser] <defunct> root 32280 0.0 0.0 0 0 ? ...