hdu--5351--MZL's Border
表示看这篇博客后找到了思路:
http://blog.csdn.net/queuelovestack/article/details/47291195
补充一下数据,方便观察规律
m LBorderm m-LBorder fibn
1 0 1 1
2 0 2 1
3 1 2 2
4 1 3 3
5 2 3 5
6 3 3 8
7 2 5 13
8 3 5 21
9 4 5 34
10 5 5 55
11 6 5 89
12 4 8 144
13 5 8 233
14 6 8 377
仔细观察一下,便会得出这样一个结论:
当我们找到第一个i满足m+1<|fibi|时,LBorderm=m-|fibi-2|(|fibi-2|表示斐波那契串fibi-2的长度)
附上代码:
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
BigInteger ar[]=new BigInteger[1000];
ar[1]=BigInteger.valueOf(1);
ar[2]=BigInteger.valueOf(2);
for(int i=3;i<1000;++i){
ar[i]=ar[i-1].add(ar[i-2]);
}
Scanner cin=new Scanner(System.in);
int t=cin.nextInt();
while(t-- >0){
int n=cin.nextInt();
BigInteger m=cin.nextBigInteger();
for(int i=1;i<1000;++i){
if(m.compareTo(ar[i]) <0 && m.compareTo(ar[i-1]) >=0){
m=m.subtract(ar[i-2]).mod(BigInteger.valueOf(258280327)); ;
break;
}
}
System.out.println(m);
}
}
}
hdu--5351--MZL's Border的更多相关文章
- 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] ...
- HDU 5351——MZL's Border——————【高精度+找规律】
MZL's Border Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 多校-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 ...
- 2015 Multi-University Training Contest 5 1009 MZL's Border
MZL's Border Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5351 Mean: 给出一个类似斐波那契数列的字符串序列 ...
- hdu5351 MZL's Border(规律题,java)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud MZL's Border Time Limit: 2000/1000 MS (Ja ...
- Hdu 5352 MZL's City (多重匹配)
题目链接: Hdu 5352 MZL's City 题目描述: 有n各节点,m个操作.刚开始的时候节点都是相互独立的,一共有三种操作: 1:把所有和x在一个连通块内的未重建过的点全部重建. 2:建立一 ...
- Hdu 5348 MZL's endless loop (dfs)
题目链接: Hdu 5348 MZL's endless loop 题目描述: 给出一个无向图(有环,有重边),包含n个顶点,m条边,问能否给m条边指定方向,使每个顶点都满足abs(出度-入度)< ...
- hdu 5349 MZL's simple problem
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5349 MZL's simple problem Description A simple proble ...
- hdu 5343 MZL's Circle Zhou SAM
MZL's Circle Zhou 题意:给定两个长度不超过a,b(1 <= |a|,|b| <= 90000),x为a的连续子串,b为y的连续子串(x和y均可以是空串):问x+y形成的不 ...
- HDU 5344 MZL's xor (多校)[补7月28]
MZL's xor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
随机推荐
- windows下python连接oracle数据库
1.首先安装cx_Oracle包2.解压instantclient-basic-windows.x64-11.2.0.4.0.zip到c:\oracle3.拷贝instantclient_11_2下所 ...
- js将格式化的时间转换成时间戳
var timestamp1 = Date.parse(new Date(startTime)), timestamp2 = Date.parse(new Date(endTime));;consol ...
- Swift自增和自增运算
自增和自增运算 和 C 语言一样,Swift 也提供了方便对变量本身加1或减1的自增(++)和自减(--)的运算符.其操作对象可以是整形和浮点型. var i = ++i // 现在 i = 1 ...
- 【Android Developers Training】 104. 接受地点更新
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- Python 迭代器和列表解析
Python 迭代器和列表解析 1)迭代器 一种特殊的数据结构,以对象形式存在 >>> i1 = l1.__iter__() >>> i1 = iter(l1) 可 ...
- office 2013幻灯片中插入SmartArt图形时出现错误下列一个或多个文件由于包含错误而无法运行
office 2013幻灯片中插入SmartArt图形时出现错误下列一个或多个文件由于包含错误而无法运行 系统:win8 64位 PowerPoint2013 64位 在幻灯片中插入SmartArt图 ...
- CentOS 6.9 升级MySQL 5.6.36到5.7.18
CentOS 6.9 升级MySQL 5.6.36到5.7.18 MySQL 5.6.36 安装过程:http://www.cnblogs.com/imweihao/p/7156754.html 升级 ...
- 将 MacOS 默认的 PHP 版本升级到 7.*
上接:在macOS Sierra 10.12搭建PHP开发环境 设置 brew brew tap homebrew/dupes brew tap homebrew/versions brew tap ...
- 基于Node.js的微信JS-SDK后端接口实现
做了一个网站,放到线上,用微信打开,点击分享,可是分享后发给朋友的链接卡片是微信默认自带的,如下: 这标题,描述以及图片是默认自带的,丑不说,分享给别人还以为是盗号网站呢,而接入微信的JSSDK后,分 ...
- python中函数的定义,调用,全局变量,局部变量,函数的嵌套使用-初级篇
函数的基本概述 在学习函数之前,一直遵循:面向过程编程,即:根据业务逻辑从上到下实现功能,可以思考一下如果有某个功能的代码是在多个地方使用的是否可以只写一次?此时的代码该如何定义.先观察以下的案例: ...