题意:给你一个经典的汉诺塔递归程序,问你最少几步使得三个柱子上的盘子数量相同。(保证最开始盘子数量可以被3整除)

规律:ans(n)=2^(2*n/3-1)+t(n/3)。

t(1)=0.

t(n)=

t(n-1)+1,n为偶数

t(n-1)*4+2,n为奇数。

Java文件读写主要有以下两种方法,第二种,输出格式更随心所欲,更实用:

import java.util.*;
import java.io.*;
import java.math.*; public class Main{
public static void main(String[] argc){
BigInteger[] t=new BigInteger[305];
BigInteger[] pw=new BigInteger[305];
t[1]=BigInteger.ZERO;
for(int i=2;i<=100;++i){
if(i%2==0){
t[i]=t[i-1].add(BigInteger.ONE);
}
else{
t[i]=t[i-1].multiply(BigInteger.valueOf(4l)).add(BigInteger.valueOf(2l));
}
}
pw[0]=BigInteger.ONE;
for(int i=1;i<=300;++i){
pw[i]=pw[i-1].multiply(BigInteger.valueOf(2l));
}
Scanner cin = new Scanner(System.in);
try{cin=new Scanner(new FileInputStream("input.txt"));}catch(Exception e){}
int n=cin.nextInt();
cin.close();
/*pw[2*n/3-1].add(t[n/3]).toString()*/
File file=new File("output.txt");
try{
BufferedWriter bf=new BufferedWriter(new PrintWriter(file));
bf.append(pw[2*n/3-1].add(t[n/3]).toString());
bf.close();
}
catch(Exception e){}
}
}
import java.util.*;
import java.io.*;
import java.math.*; public class Main{
public static void main(String[] argc){
BigInteger[] t=new BigInteger[305];
BigInteger[] pw=new BigInteger[305];
t[1]=BigInteger.ZERO;
for(int i=2;i<=100;++i){
if(i%2==0){
t[i]=t[i-1].add(BigInteger.ONE);
}
else{
t[i]=t[i-1].multiply(BigInteger.valueOf(4l)).add(BigInteger.valueOf(2l));
}
}
pw[0]=BigInteger.ONE;
for(int i=1;i<=300;++i){
pw[i]=pw[i-1].multiply(BigInteger.valueOf(2l));
}
Scanner cin = new Scanner(System.in);
try{cin=new Scanner(new FileInputStream("input.txt"));}catch(Exception e){}
int n=cin.nextInt();
cin.close();
/*pw[2*n/3-1].add(t[n/3]).toString()*/
//File file=new File("output.txt");
try{
FileWriter fw = new FileWriter("output.txt", true);
PrintWriter cout = new PrintWriter(fw);
cout.println(pw[2*n/3-1].add(t[n/3]));
cout.flush();
//BufferedWriter bf=new BufferedWriter(new PrintWriter(file));
//bf.append(pw[2*n/3-1].add(t[n/3]).toString());
//bf.close();
}
catch(Exception e){}
}
}

【高精度】【找规律】Gym - 101243B - Hanoi tower的更多相关文章

  1. 递推+高精度+找规律 UVA 10254 The Priest Mathematician

    题目传送门 /* 题意:汉诺塔问题变形,多了第四个盘子可以放前k个塔,然后n-k个是经典的汉诺塔问题,问最少操作次数 递推+高精度+找规律:f[k]表示前k放在第四个盘子,g[n-k]表示经典三个盘子 ...

  2. bzoj 1002 [FJOI2007]轮状病毒 高精度&&找规律&&基尔霍夫矩阵

    1002: [FJOI2007]轮状病毒 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2234  Solved: 1227[Submit][Statu ...

  3. HDU 5351——MZL's Border——————【高精度+找规律】

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

  4. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

  5. 【洛谷】2144:[FJOI2007]轮状病毒【高精度】【数学推导??(找规律)】

    P2144 [FJOI2007]轮状病毒 题目描述 轮状病毒有很多变种.许多轮状病毒都是由一个轮状基产生.一个n轮状基由圆环上n个不同的基原子和圆心的一个核原子构成.2个原子之间的边表示这2个原子之间 ...

  6. [FJOI2007]轮状病毒 题解(dp(找规律)+高精度)

    [FJOI2007]轮状病毒 题解(dp(找规律)+高精度) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1335733 没什么好说的,直接把规律找出来,有 ...

  7. codeforces Gym 100418D BOPC 打表找规律,求逆元

    BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?c ...

  8. 打表找规律C - Insertion Sort Gym - 101955C

    题目链接:https://cn.vjudge.net/contest/273377#problem/C 给你 n,m,k. 这个题的意思是给你n个数,在对前m项的基础上排序的情况下,问你满足递增子序列 ...

  9. bzoj1002 [FJOI2007]轮状病毒——找规律+高精度

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1002 打表找规律,似乎是这样:https://blog.csdn.net/fzhvampir ...

随机推荐

  1. Shuffle Cards(牛客第三场+splay)

    题目: 题意:将1~n的数进行m次操作,每次操作将第pi位到pi+si-1位的数字移到第一位,求最后的排列. 思路:现在还没不会写splay,在知道这是splay模板题后找了一波别人的模板,虽然过了, ...

  2. 【EverydaySport】健身笔记——人体肌肉分解图

    正面 背面 大肌肉群:胸.背.腿大肌肉群. 建议一周锻炼一次. 小肌肉群:肩.二头肌.三头肌.小臂.小腿.腹肌小肌肉群. 可以一周安排两次. 小腿.小臂肌群属于耐受肌群可以一周安排3次. 建议初学者就 ...

  3. 增大dma的分配

    前言 项目中需要通过驱动与fpga通讯,获取fpga往内存里写的数据.因为数据量比较大,需要驱动分配600多M的内存给fpga来写数据,且因为是与fpga通讯,需要连续的内存,还得是uncached的 ...

  4. sicily 1009. Mersenne Composite N

    Description One of the world-wide cooperative computing tasks is the "Grand Internet Mersenne P ...

  5. bzoj 1015 星球大战starwar

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1015 题解: 如果按照题目的意思,每次删点.删边太困难了……于是采用逆向思维,构造出最后的 ...

  6. C基础 大文件读取通过标准库

    引言 - 问题的构建 C大部分读取文件的时候采用fgetc, 最近在使用过程中发现性能不是很理想.都懂得fgetc每次只能读取一个字符, IO操作太频繁. 所以性能低. 本文希望通过标准库函数frea ...

  7. 用Python写个自动ssh登录远程服务器的小工具

    很多时候我们喜欢在自己电脑的终端直接ssh连接Linux服务器,而不喜欢使用那些有UI界面的工具区连接我们的服务器.可是在终端使用ssh我们每次都需要输入账号和密码,这也是一个烦恼,所以我们可以简单的 ...

  8. 【mongo】启动mongo

    输入mongo应该就可以启动了.但是我得到了一个报错信息. Failed global initialization: BadValue Invalid or no user locale set. ...

  9. js字符串与Unicode编码互相转换

    ).toString() "597d" 这段代码的意思是,把字符'好'转化成Unicode编码,toString()就是把字符转化成16进制了 看看charCodeAt()是怎么个 ...

  10. python接口自动化13-data和json参数傻傻分不清【转载】

    转至博客:上海-悠悠 前言 在发post请求的时候,有时候body部分要传data参数,有时候body部分又要传json参数,那么问题来了:到底什么时候该传json,什么时候该传data? 一.识别j ...