题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1041

题意:电脑中存在数字1,进行扩展操作,如果遇到1变为“01”,如果遇到0,变为“10”,经过一次变换称为“01”,两次“1001”,三次“01101001”,

求经过n次变换,得到的01序列中有多少对相邻的0。

思路:先打表得到规律1,1,3,5,11,21,43……

找规律可以发现

1*2+1=3;

1*2+3=5;

3*2+5=11;

5*2+11=21;

……;

之后就是求和的事了,由于结果过大,用大数做就行了。

#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
string str[];
string add(string s1,string s2)
{
if(s1.length()<s2.length())
{
string tmp=s1;
s1=s2;
s2=tmp;
}
int l1=s1.length(),l2=s2.length(),i,j;
for(i=l1-,j=l2-;i>=;i--,j--)
{
s1[i]=char(s1[i]+(j>=?s2[j]-'':));
if(s1[i]-''>=)
{
s1[i]=char((s1[i]-'')%+'');
if(i) s1[i-]++;
else s1=""+s1;
}
}
return s1;
}
int main(void)
{
str[]="",str[]="",str[]="",str[]="",str[]="",str[]="";
for(int i=;i<=;i++)
{
str[i]=add(add(str[i-],str[i-]),str[i-]);
}
int n;
while(~scanf("%d",&n))
{
cout<<str[n]<<endl;
}
return ;
}

hdu-1041(大数模板)的更多相关文章

  1. hdu 5429(大数模板)

    题意:判断是否是等比数列 a[i] * a[i] = a[i+1] * a[i-1]   +   部分为0 的情况 /*  表示还没学java.... ,模板来自NK_test #include &l ...

  2. HDU 1134 Game of Connections(卡特兰数+大数模板)

    题目代号:HDU 1134 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1134 Game of Connections Time Limit: 20 ...

  3. hdu 5429 Geometric Progression(存个大数模板)

    Problem Description Determine whether a sequence is a Geometric progression or not. In mathematics, ...

  4. Hdu 4762 网络赛 高精度大数模板+概率

    注意题目中的这句话he put the strawberries on the cake randomly one by one,第一次选择草莓其实有N个可能,以某一个草莓为开头,然后顺序的随机摆放, ...

  5. 【集训笔记】【大数模板】特殊的数 【Catalan数】【HDOJ1133【HDOJ1134【HDOJ1130

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3324 http://blog.csdn.net/xymscau/artic ...

  6. hdu1042(大数模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 在网上找了个大数模板方便以后用得到. #include<iostream> #inc ...

  7. hdu 5047 大数找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5047 找规律 信kuangbin,能AC #include <stdio.h> #include & ...

  8. hdu 5050 大数

    http://acm.hdu.edu.cn/showproblem.php?pid=5050 大数模板最大公约数 信kuangbin,能AC #include <cstdio> #incl ...

  9. 大数模板 (C ++)

    上次BC遇到一个大数题目,没有大数模板和不会使用JAVA的同学们GG了,赛后从队友哪里骗出大数模板.2333333,真的炒鸡nice(就是有点长),贴出来分享一下好辣. //可以处理字符串前导零 #i ...

  10. hdu 4759 大数+找规律 ***

    题目意思很简单. 就是洗牌,抽出奇数和偶数,要么奇数放前面,要么偶数放前面. 总共2^N张牌. 需要问的是,给了A X B Y  问经过若干洗牌后,第A个位置是X,第B个位置是Y 是不是可能的. Ja ...

随机推荐

  1. Codeforces Beta Round #63 (Div. 2)

    Codeforces Beta Round #63 (Div. 2) http://codeforces.com/contest/69 A #include<bits/stdc++.h> ...

  2. 【js语法】array

    array操作说明 链接:http://www.w3school.com.cn/jsref/jsref_obj_array.asp 函数说明: concat():把两个array连接起来 join() ...

  3. 【centos】centos命令总结(持续更新)

    1.查看系统版本命令 转自:https://blog.csdn.net/networken/article/details/79771212 .查看内核版本 [root@localhost ~]# u ...

  4. Django的rest_framework的视图之Mixin类编写视图源码解析

    Mixin类编写视图 我们这里用auther表来做演示,先为auther和autherdetail写2个url url(r'^autherdetail/(?P<id>\d+)', view ...

  5. 开机进入boot menu和application menu,无法开机

        1.开机点击F1进入到bios界面 2.进入Security—Secure Boot—Disabled 如果不修改Secure boot选项为Disabled,在光驱引导时可能会出现报错 3. ...

  6. 6-完美解决Error:SSL peer shut down incorrectly

    转载自: 完美解决Error:SSL peer shut down incorrectly 打开gradle文件夹下的gradle-wrapper文件 修改其中的配置文件将红色区域修改为http:// ...

  7. centos7下apache2.4反向代理

    apache安装目录在/data/apache24,这里就不介绍apache的安装了. 一.反向代理配置 在/data/apache24/conf/extra下创建htttpd-proxy.conf文 ...

  8. (IOS可自动播放)使用bxslider做了一个切换图片跟随播放MP3的功能

    代码: <!DOCTYPE html> <html lang="zh-Hans"> <head> <meta charset=" ...

  9. 模块二 hashlib模块、configparser模块、logging模块

    算法介绍 Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. 什么是摘要算法呢?摘要算法又称哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长度固定的数据串(通常 ...

  10. 10.22JS日记

    1.js数据类型分析 (1)基础类型:string.number.boolean.null.undefined (2)引用类型:object-->json.array... 2.点运算  xxx ...