递推+高精度+找规律 UVA 10254 The Priest Mathematician
/*
题意:汉诺塔问题变形,多了第四个盘子可以放前k个塔,然后n-k个是经典的汉诺塔问题,问最少操作次数
递推+高精度+找规律:f[k]表示前k放在第四个盘子,g[n-k]表示经典三个盘子,2 ^ (n - k) - 1
所以f[n] = min (f[k] * 2 + g[n-k]),n<=10000,所要要用高精度,另外打表能看出规律
*/
/************************************************
* Author :Running_Time
* Created Time :2015-8-18 9:14:21
* File Name :UVA_10254.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ; struct bign {
short s[MAXN] , len ;
bign () { memset ( s , , sizeof ( s ) ) ; len = ; }
bign operator = (const char *num) {
len = strlen ( num ) ;
for ( int i = ; i < len ; i ++ ) s[i] = num[len-i-] - '' ;
return *this ;
}
bign operator = (int num) {
char s[MAXN];
sprintf (s , "%d" , num);
*this = s ;
return *this ;
}
bign(const char *num) { *this = num ; }
bign(int num) { *this = num ; }
string str () const {
string res ;
res = "" ;
for (int i = ; i < len; i ++) res = (char) (s[i] + '') + res ;
if (res == "") res = '';
return res ;
}
bign operator + (const bign& b) const {
bign c ;
c.len = ;
for(int i = , g = ; g || i < max (len, b.len); i ++) {
int x = g ;
if (i < len) x += s[i] ;
if (i < b.len) x += b.s[i] ;
c.s[c.len++] = x % ;
g = x / ;
}
return c ;
}
void print() {
for(int i = len - ; i >= ; i --) printf("%hd", s[i]);
printf("\n");
}
}f[]; int main(void) { //UVA 10254 The Priest Mathematician
bign g = ; f[] = ;
for (int i=, j=; i<=; j++, g=g+g) {
for (int k=; k<=j && i<=; k++,i++) {
f[i] = f[i-] + g;
}
}
int n;
while (scanf ("%d", &n) == ) {
f[n].print ();
} return ;
}
递推+高精度+找规律 UVA 10254 The Priest Mathematician的更多相关文章
- POJ 2229 Sumsets(递推,找规律)
构造,递推,因为划分是合并的逆过程,考虑怎么合并. 先把N展开成全部为N个1然后合并,因为和顺序无关,所以只和出现次数有关情况有点多并且为了避免重复,分类,C[i]表示序列中最大的数为2^i时的方案数 ...
- HDU 4291 A Short problem 短问题 (递推,找规律)
题意: 给出递推式 g(n) = 3g(n - 1) + g(n - 2),且g(1) = 1,g(0) = 0.求g( g( g(n))) mod 109 + 7. 思路: 要求的g( g( g(n ...
- UVA 10254 - The Priest Mathematician (dp | 汉诺塔 | 找规律 | 大数)
本文出自 http://blog.csdn.net/shuangde800 题目点击打开链接 题意: 汉诺塔游戏请看 百度百科 正常的汉诺塔游戏是只有3个柱子,并且如果有n个圆盘,至少需要2^n- ...
- PKU 2506 Tiling(递推+高精度||string应用)
题目大意:原题链接有2×1和2×2两种规格的地板,现要拼2×n的形状,共有多少种情况,首先要做这道题目要先对递推有一定的了解.解题思路:1.假设我们已经铺好了2×(n-1)的情形,则要铺到2×n则只能 ...
- [luogu]P1066 2^k进制数[数学][递推][高精度]
[luogu]P1066 2^k进制数 题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻 ...
- BZOJ 1002 FJOI2007 轮状病毒 递推+高精度
题目大意:轮状病毒基定义如图.求有多少n轮状病毒 这个递推实在是不会--所以我选择了打表找规律 首先执行下面程序 #include<cstdio> #include<cstring& ...
- 【BZOJ】1002: [FJOI2007]轮状病毒 递推+高精度
1002: [FJOI2007]轮状病毒 Description 给定n(N<=100),编程计算有多少个不同的n轮状病毒. Input 第一行有1个正整数n. Output 将编程计算出的不同 ...
- [BZOJ1089][SCOI2003]严格n元树(递推+高精度)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1089 分析: 第一感觉可以用一个通式求出来,但是考虑一下很麻烦,不好搞的.很容易发现最 ...
- bzoj 1002 [FJOI2007]轮状病毒 高精度&&找规律&&基尔霍夫矩阵
1002: [FJOI2007]轮状病毒 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2234 Solved: 1227[Submit][Statu ...
随机推荐
- android 自己定义水平和圆形progressbar 仅仅定义一些style就能够
效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/diss ...
- 区分Integer.getInteger和Integer.valueOf、Integer.parseInt() 的使用方法
Integer类有两个看起来很类似的静态方法,一个是Integer.getInteger(String),另外一个是Integer.valueOf(String).如果只看方法名称的话,很容易将这两个 ...
- Hashmap在JDK8中的提升
HashMap使用key的hashCode()和equals()方法来将值划分到不同的桶里. 桶的数量通常要比map中的记录的数量要稍大.这样 每一个桶包含的值会比較少(最好是一个).当通过key进行 ...
- python的序列化和反序列化以及json
python 的序列化和反序列化用于内存之间的共享,包括服务器和客户端的共享,两个Python程序之间的共享,以及以字符串的形式存储到硬盘中. pyhton 的pickle 可以对Python的各种数 ...
- 提升Android编译速度
Android codebase都非常大.编译一次都须要花非常多时间.假设是preloader/lk/bootimage还好,可是Android的话都是非常久. 实际上这个编译时间还是能够进一步缩短! ...
- centos+nginx+php-fpm+php include fastcgi_params php页面能訪问但空白,被fastcgi_params与fastcgi.conf害慘了
今天在centos上折腾这块是发现老是訪问页面时,浏览器中提示是200 ok.且訪问html后缀却是正常出现内容. 可是訪问php后缀却返回空白页面,同一时候查看全部的log没有发现不论什么出错信息; ...
- Linux 简单的Shell输出
echo:用于输出指定字符串或用于在Shell中打印Shell变量的值 语法格式:echo [选项] [参数] -n:不输出换行 linlin@ubuntu:~/linlin/text$ ...
- pat1043:输出PATest
https://www.patest.cn/contests/pat-b-practise/1043 #include "stdio.h" int main() { int i, ...
- asp.net mvc + javascript生成下载文件
近期做的是对现有项目进行重构.WEB FROM改成MVC,其实也算是推倒重来了. 里面有一个导出功能,将数据输出成txt文件,供下载.原先的做法是有一个隐藏的iframe,在这个iframe的页面中设 ...
- 打造字符界面的多媒体Linux系统
0 环境与目标 硬件:ThinkPad R52笔记本一台. 目标:字符界面的Linux系统,同时可以看图片,听音乐,看视频,无线上网,重要的是可以听着音乐编程了! 注意:本文打造的系统主要是供一个工程 ...