POJ 2506 Tiling(递推+大整数加法)
http://poj.org/problem?id=2506
题意:
思路:
递推。a[i]=a[i-1]+2*a[i-2]。
计算的时候是大整数加法。错了好久,忘记考虑1了...晕倒。
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
using namespace std; int n;
char s[][]; void cacl(int i)
{
int k;
int len1 = strlen(s[i - ]);
int len2 = strlen(s[i - ]);
int flag = ;
for (k = ; k < len2; k++)
{
int x = s[i - ][k] - '' + * (s[i - ][k] - '');
if (flag)
{
x += flag;
flag = ;
}
if (x>)
{
flag = x / ;
x = x % ;
}
s[i][k] = x + '';
}
while (k < len1)
{
int x = s[i - ][k] - '';
if (flag)
{
x += flag;
flag = ;
}
if (x>)
{
flag = x / ;
x = x % ;
}
s[i][k] = x + '';
k++;
}
if (flag) s[i][k] = flag + '';
} void init()
{
s[][] = '';
s[][] = '';
s[][] = '';
for (int i = ; i <= ; i++)
cacl(i);
} int main()
{
init();
while (cin>>n)
{
int m = strlen(s[n]);
for (int i = m-; i >= ; i--)
cout << s[n][i];
cout << endl;
}
}
POJ 2506 Tiling(递推+大整数加法)的更多相关文章
- poj 2506 Tiling 递推
题目链接: http://poj.org/problem?id=2506 题目描述: 有2*1和2*2两种瓷片,问铺成2*n的图形有多少种方法? 解题思路: 利用递推思想,2*n可以由2*(n-1)的 ...
- POJ 2506 Tiling (递推 + 大数加法模拟 )
Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7965 Accepted: 3866 Descriptio ...
- PKU 2506 Tiling(递推+高精度||string应用)
题目大意:原题链接有2×1和2×2两种规格的地板,现要拼2×n的形状,共有多少种情况,首先要做这道题目要先对递推有一定的了解.解题思路:1.假设我们已经铺好了2×(n-1)的情形,则要铺到2×n则只能 ...
- (递推 大整数) Children’s Queue hdu1297
Children’s Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 2981:大整数加法-poj
2981:大整数加法 总时间限制: 1000ms 内存限制: 65536kB 描述 求两个不超过200位的非负整数的和. 输入 有两行,每行是一个不超过200位的非负整数,可能有多余的前导0. 输 ...
- AC日记——大整数加法 openjudge 1.6 10
10:大整数加法 总时间限制: 1000ms 内存限制: 65536kB 描述 求两个不超过200位的非负整数的和. 输入 有两行,每行是一个不超过200位的非负整数,可能有多余的前导0. 输出 ...
- HDU1002——大整数加法
题目: I have a very simple problem for you. Given two integers A and B, your job is to calculate the S ...
- openjudge计算概论-大整数加法
/*=====================================================================1004:大整数加法总时间限制: 1000ms 内存限制: ...
- A——大整数加法(HDU1002)
题目: I have a very simple problem for you. Given two integers A and B, your job is to calculate the S ...
随机推荐
- 腾讯云的云数据库MYSQL配置
腾讯云的云数据库MYSQL配置
- you
抑制幽门螺旋杆菌: 1.西兰花 鲜嫩的西兰花蔬菜,含有一种物质叫异硫氰酸酯,这种物质就是幽门螺杆菌的 " 天敌 ",可达到百分百抑制的作用,甚至还有医生给了它一个最强天然抗生素的称 ...
- [py][mx]django添加后台课程机构页数据-图片上传设置
分析下课程页前台部分 机构类别-目前机构库中没有这个字段,需要追加下 所在地区 xadmin可以手动添加 课程机构 涉及到机构封面图, 即图片上传media设置, 也需要在xadmin里手动添加几条 ...
- (转)Elasticsearch NoNodeAvailableException None of the configured nodes are available
问题背景:将es部署到内网中两台服务器,其Ip地址分别为:192.111.222.5,192.111.222.1(部署方式完全一样,是将192.111.222.1服务器上es整个部署包,拷贝到了192 ...
- [LeetCode] 437. Path Sum III_ Easy tag: DFS
You are given a binary tree in which each node contains an integer value. Find the number of paths t ...
- isKindOfClass isMemeberOfClass 的区分
isKindOfClass If you use such constructs in your code, you might think it is alright to modify an ob ...
- opencv3寻找最小包围矩形在图像中的应用-滚动条
#include<opencv2/opencv.hpp> #include<iostream> #include<vector> using namespace c ...
- Ghost硬盘对拷
Ghost硬盘对拷 优点:全盘完全100%对拷,包括原有操作系统也可使用.新硬盘对拷结束后,可直接插上电脑使用.消耗时间最短. 困难:对于第一次操作Ghost对拷的新人来说,需要严格对照图片步骤教程. ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON HomMat2dRotate1
zw版[转发·台湾nvp系列Delphi例程]HALCON HomMat2dRotate1 procedure TForm1.Button1Click(Sender: TObject);var img ...
- C# Http方式下载文件到本地类改进版
在上文基础上增加了远程文件是否存在和本地文件是否存在的判断. 类代码: using System; using System.Collections.Generic; using System.Lin ...