【高精度】【找规律】Gym - 101243B - Hanoi tower
题意:给你一个经典的汉诺塔递归程序,问你最少几步使得三个柱子上的盘子数量相同。(保证最开始盘子数量可以被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的更多相关文章
- 递推+高精度+找规律 UVA 10254 The Priest Mathematician
题目传送门 /* 题意:汉诺塔问题变形,多了第四个盘子可以放前k个塔,然后n-k个是经典的汉诺塔问题,问最少操作次数 递推+高精度+找规律:f[k]表示前k放在第四个盘子,g[n-k]表示经典三个盘子 ...
- bzoj 1002 [FJOI2007]轮状病毒 高精度&&找规律&&基尔霍夫矩阵
1002: [FJOI2007]轮状病毒 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2234 Solved: 1227[Submit][Statu ...
- HDU 5351——MZL's Border——————【高精度+找规律】
MZL's Border Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- Codeforces Gym 100114 A. Hanoi tower 找规律
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...
- 【洛谷】2144:[FJOI2007]轮状病毒【高精度】【数学推导??(找规律)】
P2144 [FJOI2007]轮状病毒 题目描述 轮状病毒有很多变种.许多轮状病毒都是由一个轮状基产生.一个n轮状基由圆环上n个不同的基原子和圆心的一个核原子构成.2个原子之间的边表示这2个原子之间 ...
- [FJOI2007]轮状病毒 题解(dp(找规律)+高精度)
[FJOI2007]轮状病毒 题解(dp(找规律)+高精度) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1335733 没什么好说的,直接把规律找出来,有 ...
- codeforces Gym 100418D BOPC 打表找规律,求逆元
BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?c ...
- 打表找规律C - Insertion Sort Gym - 101955C
题目链接:https://cn.vjudge.net/contest/273377#problem/C 给你 n,m,k. 这个题的意思是给你n个数,在对前m项的基础上排序的情况下,问你满足递增子序列 ...
- bzoj1002 [FJOI2007]轮状病毒——找规律+高精度
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1002 打表找规律,似乎是这样:https://blog.csdn.net/fzhvampir ...
随机推荐
- eCharts 多个图表自适应窗口大小
单个图表自适应页面窗口只需要在创建图表节点后面添加一句代码就可以了: window.onresize = myChart.resize; 多图表要自适应页面,创建图表节点后面添加事件,并在事件函数里面 ...
- tornado简单使用
这篇适用于快速上手想了解更深:http://www.tornadoweb.cn/ https://tornado-zh.readthedocs.io/zh/latest/ Tornado 是 Fr ...
- [Leetcode Week13]Palindrome Partitioning
Palindrome Partitioning 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/palindrome-partitioning/desc ...
- python基础===【字符串】所有相关操作
#字符串的相关操作 #基本操作 #+ 字符串连接操作 str1 = '来是come走是go' str2 = '点头yes摇头no' result = str1 + str2 print(result) ...
- eComStation 1.2
https://thomas0008.ctfile.com/u/75519/87485 https://thomas0008.ctfile.com/downhtml/75519/428846/1508 ...
- 2017多校第8场 HDU 6133 Army Formations 线段树合并
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6133 题意:给你一棵n个节点的二叉树,每个节点有一个提交任务的时间,每个节点总的提交任务的罚时为:提交 ...
- Phoenix批量修改数据
很简单的一个东西,查了挺久的,浪费了很多的时间 直接用Upsert Into Select就可以了 例:把tables表中cloumn2列等于bbb的都改成aaa Upsert Into Table ...
- kivy安装
>>> os.system('pip install kivy')Collecting kivy Downloading Kivy-1.9.1-cp27-none-win_amd64 ...
- Rsync文件同步服务
Rsync简介 Rsync是一款开源的.快速的.多功能的.可实现全量及增量的本地或远程数据同步备份的优秀工具,适用于Unix/Linux/Windows等多种操作系统. Rsync的特性 支持拷贝特殊 ...
- artDialog的一些例子与一些属性的介绍。
1.支持自定义按钮 var dialog = art.dialog({ title: '警告', content: '点击管理按钮将让删除按钮可用', width: '20em', button: [ ...