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 ...
随机推荐
- 显示界面的流畅性FHHFPSIndicator
github地址https://github.com/jvjishou/FHHFPSIndicator 1.使用cocoapods pod 'FHHFPSIndicator' 使用方法: 然后在Ap ...
- 008-spring cloud gateway-路由谓词RoutePredicate、RoutePredicateFactory
一.概述 Spring Cloud Gateway将路由作为Spring WebFlux HandlerMapping基础结构的一部分进行匹配. Spring Cloud Gateway包含许多内置的 ...
- c++多线程实例
#include <windows.h> #include <stdio.h> #include <process.h> ; int g_thread_counte ...
- Java设计模式应用——观察者模式
告警结果产生后,可能需要发送短信,邮件,故障管理系统.这些转发操作不应当影响告警生成入库,并且类似事件可能根据不同场景,客户习惯不同,此时,使用观察者模式则可以很好的适应上述场景. 观察者模式应当包括 ...
- ORA-00980: 同义词转换不再有效
客户账号TB在操作软件时,报错:“[Microsoft][ODBC driver for Oracle][Oracle]ORA-00980: 同义词转换不再有效”. 使用拥有dba权限的账号sys的登 ...
- Linux基础命令---gunzip
gunzip 解压缩被gzip压缩过的文件.此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora. 1.语法 gunzip [-ac ...
- bootstrap table数据分页查询展示
index.php <html> <head> <link rel="stylesheet" href="./css/bootstrap.m ...
- ui-grid angularjs
<pre name="code" class="html"><!--ui-grid css--> <link rel=" ...
- web前端----jQuery操作标签
样式操作 样式类 addClass();// 添加指定的CSS类名. removeClass();// 移除指定的CSS类名. hasClass();// 判断样式存不存在 toggleClass() ...
- SQL 报表 --简易进销系统
模型图: -- ============================================ -- Author: lifu -- Create Date: 2017-06-18 -- D ...