南昌网络赛C.Angry FFF Party

Describe

In ACM labs, there are only few members who have girlfriends. And these people can make FFF Party angry easily. One day, FFF Party prepared a function \(F\)and a set \(S\).

\[\left\{
\begin{aligned}
1,&&n = 1,2 \\
F(n-1)+F(n-2), && n\ge3
\end{aligned}
\right.
\]

There are several unequal positive integers $ f _i$ in the set \(S\).

They calculated the value of \(W=\sum_{f\in s}{F(F(f))}\), and tried to cause \(W\)damage to those who have girlfriends. Suppose you are not a single dog and have been attacked. Now, give you the value of \(W\) and please write a program to calculate these \(fi\) in set \(S\).

Input

The first line consists of a single integer \(T\) denoting the number of test cases.

\(T\) lines follow, with an integer in each, denoting the result of \(W\).

Output

For each test case, print a sequence of space-separated integers \(fi\) satisfying the equation.

If there are more than one answers, please print the lexicographically smallest one.

If there’s no such sequence, print \(-1\) instead.

Constraints

$1\le T \le10 $

\(1\le W \leq 10^{100,000}\)

样例输入

2
1
3

样例输出

1
1 2 3

题意

给你一个很大的数,让你从斐波拉切的斐波拉切数列中选择任意多个数,使其和等于这个数。

题解

​ 本来想直接复制粘贴题目的,但是数学公式实在太恶心,复制不过来,于是就按照\(OYJY\)大佬的指示,下载了个markdown编辑器typora ,但是不知是我的linux系统不行,还是搜狗输入法不行,切换不了中文输入法,于是悲催的我只能再wps中打中文,再粘贴过去。qwq.

n天之后新发现:

原来只要不从终端打开typora就可以切换输入法啦。另外告诉各位不能显示数学公式的小伙伴,在新建随便的那个页面左栏设置默认编辑器里,需要勾选启用数学公式支持

​ 开始进入正题,通过打表 c++已选手退出群聊 发现,其实只有28个数,而且除了前五个数相差较小,后面的数基本相差巨大,也就是前面所有的数加起来都没有下一个数大。于是我们从大到小一个一个减,能减就减,到零或者剪完为止,是不是很简单,。

但是我不会 java ,于是我学了一天的 java,安装eclipse安了一下午,菜的真实,然后刷了几道水题,最终切了这道早就想切的题了。

因为输入的是字典序最小的一组解,所以当数小与\(10\)时,要打表处理

代码

import java.io.*;
import java.math.*;
import java.util.*;
public class Main { public static void main(String[] args)
{
Scanner cin=new Scanner(new BufferedInputStream(System.in)); BigInteger list[]=new BigInteger[30];
BigInteger tp[][]=new BigInteger[3][3],a[][]=new BigInteger[3][3];
int f[]=new int[30],flag=0;
a[1][1]=BigInteger.ONE; a[1][2]=BigInteger.ONE;
a[2][1]=BigInteger.ONE; a[2][2]=BigInteger.ZERO;
f[0]=0; f[1]=1; for(int i=2;i<=29;i++) f[i]=f[i-1]+f[i-2];
for(int i=1;i<=29;i++)
{
tp=MatrixPower(a,2,f[i]-1);
list[i]=tp[1][1];
}
//for(int i=1;i<=20;i++) System.out.println(list[i]);
int tot=0; tot=cin.nextInt();
while(tot>0)
{
tot=tot-1;
BigInteger n=cin.nextBigInteger();
//tp=MatrixPower(a,2,n-1);
//System.out.println(tp[1][1].toString());
flag=get_ans(n,28,list);
if (tot>0)System.out.println("");
}
}
public static int get_ans(BigInteger n,int maxn,BigInteger list[])
{
//System.out.println("now= "+n);
if (n.compareTo(BigInteger.ZERO)==0) return 0;
if (maxn==0||maxn==4)
{
System.out.print("-1");
return -1 ;
}
BigInteger a[]=new BigInteger[11];
for(int i=1;i<=10;i++) a[i]=BigInteger.valueOf(i);
if (n.compareTo(a[10])<=0)
{
//System.out.println("lalala ");
if (n.compareTo(a[1])==0)System.out.print("1");
if (n.compareTo(a[2])==0)System.out.print("1 2");
if (n.compareTo(a[3])==0)System.out.print("1 2 3");
if (n.compareTo(a[4])==0)System.out.print("1 2 4");
if (n.compareTo(a[5])==0)System.out.print("1 2 3 4");
if (n.compareTo(a[6])==0)System.out.print("1 5");
if (n.compareTo(a[7])==0)System.out.print("1 2 5");
if (n.compareTo(a[8])==0)System.out.print("1 2 3 5");
if (n.compareTo(a[9])==0)System.out.print("1 2 4 5");
if (n.compareTo(a[10])==0)System.out.print("1 2 3 4 5");
return 0;
}
for(int i=maxn;i>=1;i--)
{
if (n.compareTo(list[i])>=0)
{
BigInteger tt=n.subtract(list[i]);
int pd=get_ans(n.subtract(list[i]),i-1,list);
if (pd==0 && tt.compareTo(BigInteger.ZERO)>0)System.out.printf(" ");
if (pd==0)System.out.printf("%d",i);
if (pd==0)return 0;
return -1;
}
}
return 0;
}
public static BigInteger[][] MatrixMultiply(BigInteger a[][],BigInteger b[][],int n,int p,int m)
{
BigInteger c[][]=new BigInteger[n+1][m+1];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
c[i][j]=BigInteger.ZERO;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
for(int k=1;k<=p;k++)
c[i][j]=c[i][j].add(a[i][k].multiply(b[k][j]));
return c;
}
public static BigInteger[][] MatrixPower(BigInteger a[][],int n,int p)
{
BigInteger ans[][]=new BigInteger[n+1][n+1];
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if (i==j)ans[i][j]=BigInteger.ONE;
else ans[i][j]=BigInteger.ZERO;
while(p>0)
{
if ((p&1)==1)ans=MatrixMultiply(ans,a,n,n,n);
p=p/2;
a=MatrixMultiply(a,a,n,n,n);
}
return ans;
}
}

南昌网络赛C.Angry FFF Party的更多相关文章

  1. dp--2019南昌网络赛B-Match Stick Game

    dp--2019南昌网络赛B-Match Stick Game Xiao Ming recently indulges in match stick game and he thinks he is ...

  2. 线段树+单调栈+前缀和--2019icpc南昌网络赛I

    线段树+单调栈+前缀和--2019icpc南昌网络赛I Alice has a magic array. She suggests that the value of a interval is eq ...

  3. 2019南昌网络赛I:Yukino With Subinterval(CDQ) (树状数组套主席树)

    题意:询问区间有多少个连续的段,而且这段的颜色在[L,R]才算贡献,每段贡献是1. 有单点修改和区间查询. 思路:46min交了第一发树套树,T了. 稍加优化多交几次就过了. 不难想到,除了L这个点, ...

  4. ACM-ICPC 2019南昌网络赛F题 Megumi With String

    ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...

  5. ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval

    ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval 题目大意:给一个长度为n,值域为[1, n]的序列{a},要求支持m次操作: 单点修改 1 pos val 询 ...

  6. 南昌网络赛 H The Nth Item

    南昌网络赛The Nth Item 暴力快速幂+unordered_map记忆化 注意:记忆化不能写到快速幂求解函数里,不断调用函数会造成很大的时间浪费 #include<bits/stdc++ ...

  7. 分治维护dp——19南昌网络赛C/cf750E

    南昌网络赛,是cf的原题 第一次做到这种题,所以认真想了下,每次给一个询问[L,R],要求出这个区间里有2017子序列,但是不能有2016子序列需要删掉的最少元素个数 首先如果我们之询问一小段区间[L ...

  8. 2019 ICPC 南昌网络赛

    2019 ICPC 南昌网络赛 比赛时间:2019.9.8 比赛链接:The 2019 Asia Nanchang First Round Online Programming Contest 总结 ...

  9. Magic Master(2019年南昌网络赛E题+约瑟夫环)

    目录 题目链接 题意 思路 代码 题目链接 传送门 题意 初始时你有\(n\)张牌(按顺序摆放),每一次操作你将顶端的牌拿出,然后按顺序将上面的\(m\)张牌放到底部. 思路 首先我们发下拿走\(1\ ...

随机推荐

  1. JVM基本讲解

    1.数据类型 java虚拟机中,数据类型可以分为两类:基本类型和引用类型. 基本类型的变量保存原始值,即:它代表的值就是数值本身,而引用类型的变量保存引用值. “引用值”代表了某个对象的引用,而不是对 ...

  2. ARTS打卡计划第十四周

    Algorithms: https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/ Review: “How to write ...

  3. mac使用frida

    mac使用frida 安装 https://github.com/frida/frida/releases 根据手机的cpu的版本,选择相应的文件,一般通过手机信息可以看到 我这里是frida-ser ...

  4. maven坐标及依赖范围的学习(1)

    首先,我们先了解什么是maven的坐标(重中之重): 在这里我们可以看到那三个红色的行,基本是pom.xml中出现的最多的配置     例如这个配置:这里我们可以看到我们这个项目的pom文件中,他对名 ...

  5. LeetCode687----最长同值路径

    给定一个二叉树,找到最长的路径,这个路径中的每个节点具有相同值. 这条路径可以经过也可以不经过根节点. 注意:两个节点之间的路径长度由它们之间的边数表示. 示例 1: 输入: 5 / \ 4 5 / ...

  6. Flume-几种拓扑结构

    一.串联 Flume Agent 连接 这种模式是将多个 flume 顺序连接起来了,从最初的 source 开始到最终 sink 传送的目的存储系统.此模式不建议桥接过多的 flume 数量,flu ...

  7. article收藏

    sca https://github.com/spring-cloud-incubator/spring-cloud-alibaba spring-cloud-document https://git ...

  8. 移动端——meta标签

    meta标签主要辅助HTML结构层的.meta标签不管在互联网前端还是在移动端都起了很重要的作用. <meta http-equiv="Content-type" conte ...

  9. 深度学习之加载VGG19模型获取特征图

    1.加载VGG19获取图片特征图 # coding = utf-8 import tensorflow as tf import numpy as np import matplotlib.pyplo ...

  10. 一首好听的摇滚歌曲(Ever Dream),以及优美的译作

     送上一首好听的摇滚歌曲,以及优美的译作.祝大家新年快乐.happy new year!  [ti:Ever Dream][ar:Nightwish][al:Century Child][by:吖光] ...