题目链接 https://nanti.jisuanke.com/t/38222

题意:

定义函数:

$$F(n)=\left\{
\begin{aligned}
1, \quad n=1,2 \\
F(n-1)+F(n-2),\quad n\geq3 \quad
\end{aligned}
\right.
$$

给定一个W 找到一个字典序最小的集合S使得

$$W=\sum_{f\in S}F(F(f))$$

$1\leq  T\leq 10$

$1\leq  W\leq 10^{100,000}$

解析:java大数打表可以发现 当f >28时已经超过W上界了,所以快速幂求出来前28项就好了,数增加的非常快,只有当W<=10时才有 多个解的情况

所以从大的开始减,当减到第五项的时候 再分类讨论一下就好了。

AC代码

import java.util.*;
import java.math.*; public class Main { static class Matrix {
public static int maxn = ;
BigInteger a[][] = new BigInteger [maxn][maxn];
public void init() {
for (int i = ; i < maxn; ++i) for (int j = ; j < maxn; ++j) a[i][j] = BigInteger.ZERO;
}
public void _init() {
init();
for (int i = ; i < maxn; ++i) a[i][i] = BigInteger.ONE;
}
public static Matrix mul(Matrix A, Matrix B) {
Matrix res = new Matrix();
res.init();
for (int i = ; i < maxn; ++i) {
for (int j = ; j < maxn; ++j) {
for (int k = ; k < maxn; ++k) {
res.a[i][k] = res.a[i][k].add(A.a[i][j].multiply(B.a[j][k]));
}
}
}
return res;
}
public static Matrix q_pow(Matrix A, BigInteger k) {
Matrix res = new Matrix();
res._init();
while(k.compareTo(BigInteger.ZERO) > ) {
if(k.mod(BigInteger.valueOf()).compareTo(BigInteger.ZERO) > ) res = mul(res, A);
A = mul(A, A);
k = k.shiftRight();
}
return res;
}
}
public static BigInteger get_fib(BigInteger n) {
if(n.compareTo(BigInteger.ONE) == ) return BigInteger.ONE;
if(n.compareTo(BigInteger.valueOf()) == ) return BigInteger.ONE;
Matrix A = new Matrix();
A.a[][] = BigInteger.ZERO;
A.a[][] = A.a[][] = A.a[][] = BigInteger.ONE;
A = Matrix.q_pow(A, n.subtract(BigInteger.valueOf()));
return A.a[][].add(A.a[][]);
} public static void main(String[] args) { BigInteger f[] = new BigInteger[];
int ans[] = new int[];
Scanner cin = new Scanner(System.in);
int T = cin.nextInt();
for (int i = ; i <= ; ++i) {
f[i] = Main.get_fib(Main.get_fib(BigInteger.valueOf(i)));
}
while(T--> ) {
BigInteger W = cin.nextBigInteger();
int cnt = ;
for (int i = ; i >= ; --i) {
if(f[i].compareTo(W) <= ) {
ans[++cnt] = i;
W = W.subtract(f[i]);
}
}
if(W.compareTo(BigInteger.valueOf()) == ) {
ans[++cnt] = ;
}
else if(W.compareTo(BigInteger.valueOf()) == ){
ans[++cnt] = ;
ans[++cnt] = ;
}
else if(W.compareTo(BigInteger.valueOf()) == ) {
ans[++cnt] = ;
ans[++cnt] = ;
ans[++cnt] = ;
}
else if(W.compareTo(BigInteger.valueOf()) == ) {
ans[++cnt] = ;
ans[++cnt] = ;
ans[++cnt] = ;
}
else if(W.compareTo(BigInteger.valueOf()) == ) {
ans[++cnt] = ;
ans[++cnt] = ;
ans[++cnt] = ;
ans[++cnt] = ;
}
else if(W.compareTo(BigInteger.valueOf()) == ) {
ans[++cnt] = ;
ans[++cnt] = ;
}
else if(W.compareTo(BigInteger.valueOf()) == ) {
ans[++cnt] = ;
ans[++cnt] = ;
ans[++cnt] = ;
}
else if(W.compareTo(BigInteger.valueOf()) == ) {
ans[++cnt] = ;
ans[++cnt] = ;
ans[++cnt] = ;
ans[++cnt] = ;
}
else if(W.compareTo(BigInteger.valueOf()) == ) {
ans[++cnt] = ;
ans[++cnt] = ;
ans[++cnt] = ;
ans[++cnt] = ;
}
else if(W.compareTo(BigInteger.valueOf()) == ) {
ans[++cnt] = ;
ans[++cnt] = ;
ans[++cnt] = ;
ans[++cnt] = ;
ans[++cnt] = ;
}
else if(W.compareTo(BigInteger.ZERO)!=){
System.out.println(-);
continue;
}
for (int i = cnt; i >= ; --i) {
if(i == )
System.out.println(ans[i]);
else
System.out.print(ans[i]+" ");
}
}
} }

代码参考 https://www.cnblogs.com/widsom/p/10742707.html

2019南昌邀请赛 C. Angry FFF Party 大数矩阵快速幂+分类讨论的更多相关文章

  1. 2019.02.11 bzoj4818: [Sdoi2017]序列计数(矩阵快速幂优化dp)

    传送门 题意简述:问有多少长度为n的序列,序列中的数都是不超过m的正整数,而且这n个数的和是p的倍数,且其中至少有一个数是质数,答案对201704082017040820170408取模(n≤1e9, ...

  2. 2019南昌邀请赛网络预选赛 M. Subsequence

    传送门 题意: 给出一个只包含小写字母的串 s 和n 个串t,判断t[i]是否为串 s 的子序列: 如果是,输出"YES",反之,输出"NO": 坑点: 二分一 ...

  3. BNUOJ 34985 Elegant String 2014北京邀请赛E题 矩阵快速幂

    题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 题目大意:问n长度的串用0~k的数字去填,有多少个串保证任意子串中不包含0~k的 ...

  4. 2019南昌邀请赛网络预选赛 I. Max answer(单调栈+暴力??)

    传送门 题意: 给你你一序列 a,共 n 个元素,求最大的F(l,r): F(l,r) = (a[l]+a[l+1]+.....+a[r])*min(l,r); ([l,r]的区间和*区间最小值,F( ...

  5. 2019南昌邀请赛网络预选赛 J.Distance on the tree(树链剖分)

    传送门 题意: 给出一棵树,每条边都有权值: 给出 m 次询问,每次询问有三个参数 u,v,w ,求节点 u 与节点 v 之间权值 ≤ w 的路径个数: 题解: 昨天再打比赛的时候,中途,凯少和我说, ...

  6. POJ-2796 & 2019南昌邀请赛网络赛 I. 区间最大min*sum

    http://poj.org/problem?id=2796 https://nanti.jisuanke.com/t/38228 背景 给定一个序列,对于任意区间,min表示区间中最小的数,sum表 ...

  7. 2019南昌邀请赛 L 计算几何 G(待补)

    #include<bits/stdc++.h> const double PI=acos(-1.0); ; using namespace std; struct Point { doub ...

  8. 2019南昌邀请赛网络赛:J distance on the tree

    1000ms 262144K   DSM(Data Structure Master) once learned about tree when he was preparing for NOIP(N ...

  9. [2019南昌邀请赛网络赛D][dp]

    https://nanti.jisuanke.com/t/38223 Xiao Ming recently indulges in match stick game and he thinks he ...

随机推荐

  1. Python中类的声明,使用,属性,实例属性,计算属性及继承,重写

    Python中的类的定义以及使用: 类的定义: 定义类 在Python中,类的定义使用class关键字来实现 语法如下: class className: "类的注释" 类的实体 ...

  2. Python中的可迭代对象,迭代器与生成器

    先来看一张概览图,关于容器(container).可迭代对象(Iterable).迭代器(iterator).生成器(generator). 一.容器(container) 容器就是一个用来存储多个元 ...

  3. HTTP和HTTPS以及两者的区别

    HTTP:是互联网上的应用广泛的一种网络协议,是一个客户端和服务器端请求和应答的传输协议,它可以使浏览器更加高效,使网络传输减少. HTTPS:是以安全为目标的HTTP通道,简单讲是HTTP的安全版, ...

  4. 百度地图的API接口----多地址查询和经纬度

    最近看了百度地图的API的接口,正想自己做点小东西,主要是多地址查询和经纬度坐标跟踪, 下面的代码直接另存为html就可以了,目前测试Chrome和360浏览器可以正常使用. <!DOCTYPE ...

  5. WordCount 2.0(结对项目)

    序言 合作伙伴 201631062220      201631062120 项目码云地址: https://gitee.com/zhege/WordCount 作业详细要求 系统分析与设计结对项目 ...

  6. install cinnamon on ubuntu 14.04

    emotion: I feel not comfortable with ubuntu 14.04 default desktop unity,i still look for a alternati ...

  7. 实现chrome多用户独立cookie

    2018-02-08 10:58:57 在浏览器设置中添加一个用户并创建桌面快捷方式,属性中我们可以发现 "C:\Program Files (x86)\Google\Chrome\Appl ...

  8. OGNL表达式详解

    OGNL表达式标签中的值有三种: 1.直接是OGNL表达式. 2.字符串需转义自OGNL表达式. 1)OGNL表达式转换为字符串显示,需要用''(单引号)引起来. 2)转为OGNL表达式的字符串,需要 ...

  9. WTForms 表单动态验证

    class UserDetails(Form): group_id = SelectField(u'Group', coerce=int) def edit_user(request, id): us ...

  10. HDU——2068RPG的错排(错排公式)

    RPG的错排 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...