Computer Transformation

http://acm.hdu.edu.cn/showproblem.php?pid=1041

Problem Description
A sequence consisting of one digit, the number 1 is initially written into a computer. At each successive time step, the computer simultaneously tranforms each digit 0 into the sequence 1 0 and each digit 1 into the sequence 0 1. So, after the first time step, the sequence 0 1 is obtained; after the second, the sequence 1 0 0 1, after the third, the sequence 0 1 1 0 1 0 0 1 and so on.

How many pairs of consequitive zeroes will appear in the sequence after n steps?

 
Input
Every input line contains one natural number n (0 < n ≤1000).
 
Output
For each input n print the number of consecutive zeroes pairs that will appear in the sequence after n steps.
 
Sample Input
2
3
 
Sample Output
1
1
 
 解题思路:找出规律,F[n] = F[n-2] + 2n-3, 不过不能直接一起算,因为可能会超时;我们可以这样F[n] = F[n-2] + G[n-3]; (其中F[]代表多少对0,G[]代表有多少个1);
G[n] = G[n-1] + G[n-1];所以这里就只需要大数加法就够了!
 
解题代码:

 #include <stdio.h>
#include <iostream>
#include <math.h>
#include <string.h>
#define CLE(name) memset(name, 0, sizeof (name))
using namespace std; typedef __int64 LL;
const int max_n = ; string F[*max_n];
string P2[*max_n];
int num1[max_n], num2[max_n]; string add(string a, string b)
{
CLE(num1);
CLE(num2);
int len1 = a.length();
int len2 = b.length();
int k = ;
for (int i = len1 - ; i >= ; i --)
{
num1[k++] = a[i] - '';
}
k = ;
for (int i = len2 - ; i >= ; i --)
{
num2[k++] = b[i] - '';
}
int up = ;
for (int i = ; i < max_n/; i ++)
{
num1[i] = num1[i] + num2[i] + up;
up = num1[i]/;
num1[i] %= ; }
for (k = max_n - ; k >= ; k --)
{
if (num1[k] != )
break;
}
a = "";
for (; k >= ; k --)
a += num1[k] + '';
return a;
} void pow2()
{
P2[] = "";
P2[] = "";
for (int i = ; i <= ; i ++)
{
P2[i] = add(P2[i-], P2[i-]);
}
}
void deel()
{
F[] = "";
F[] = "";
F[] = "";
for (int i = ; i <= max_n; i ++)
{
F[i] = add(F[i-], P2[i-]);
}
return;
} int main()
{
int n;
pow2();
deel();
while (~scanf ("%d", &n))
{
cout << F[n] << endl;
}
return ;
}

HDU 1041 Computer Transformation (简单大数)的更多相关文章

  1. HDU 1041 Computer Transformation(找规律加大数乘)

    主要还是找规律,然后大数相乘 #include<stdio.h> #include<string.h> #include<math.h> #include<t ...

  2. HDU 1041 Computer Transformation 数学DP题解

    本题假设编程是使用DP思想直接打表就能够了. 假设是找规律就须要数学思维了. 规律就是看这些连续的0是从哪里来的. 我找到的规律是:1经过两次裂变之后就会产生一个00: 00经过两次裂变之后也会产生新 ...

  3. HDU 1041 Computer Transformation

    这道题目的意思是:一开始有一个数字 1 ,在接下来的时间中,计算机会按照如下规则进行扩展:                0 –> 1 0                1 –> 0 1 ...

  4. Computer Transformation(简单数学题+大数)

    H - Computer Transformation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &am ...

  5. hdu_1041(Computer Transformation) 大数加法模板+找规律

    Computer Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/ ...

  6. (大数)Computer Transformation hdu1041

    Computer Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/ ...

  7. Computer Transformation(规律,大数打表)

    Computer Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/ ...

  8. hdu 1041(递推,大数)

    Computer Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/ ...

  9. hdu 3695 Computer Virus on Planet Pandora(AC自己主动机)

    题目连接:hdu 3695 Computer Virus on Planet Pandora 题目大意:给定一些病毒串,要求推断说给定串中包括几个病毒串,包括反转. 解题思路:将给定的字符串展开,然后 ...

随机推荐

  1. java 通过zxing生成二维码

    1.基本类提供二维码生成工具类 package com.green.util; import java.awt.image.BufferedImage; import java.io.ByteArra ...

  2. 基于socket的客户端和服务端聊天机器人

    服务端代码如下: using System;using System.Net;using System.Net.Sockets;using System.Text;using System.Threa ...

  3. 关于android WebViewClient的方法解释

    1.public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true ...

  4. 基于NPOI导出Excel

    在上一篇文章[关于大数据的查询与导出]中,提到了使用NPOI组件导出Excel,本想上次一起分享给大家,无奈最近比较忙,今天抽空整理了下,分享出来. 预置填充模板,并且需要支持公式计算; 可导入图片; ...

  5. 37.altium designer中的class和rules?

    在布局布线工程中,遇到复杂工程时,难免要进行class和rules的设置,经过试验证明,class和rules的子目录是有优先级的.

  6. maven属性

    Maven内置了三大特性:属性.Profile和资源过滤来支持构建的灵活性. 内置属性:主要有两个常用内置属性 ${basedir}表示项目根目录,即包含pom.xml文件的目录 ${version} ...

  7. 将inline、template声明和定义在头文件中

    如果要在要在源文件(a.cpp)中内联的展开一个函数(fun),则该源文件(a.cpp)中必须包含此函数(fun)的定义.如果要在多个文件中内联的展开fun,则在所有的源文件中都必须包含fun的定义. ...

  8. cocos中使用VS自动创建工程的方法

    为了省事,直接用VS编写了一小段代码,将cocos手动创建工程的命令改用system来执行,免去了手动输入命令的麻烦 其中: -d F:\\cocos2d-x-3.2-projects 是你要存放的工 ...

  9. <梦断代码>读后感2

    <梦断代码>这本书读了一半,我的心情久久不能平静. 为什么好软件如此难做?这是我本人,我想也是很多人都在苦苦思索的一个问题,虽然没有人能有完全确定的答案,但通过书中的记述,和个人思考,还是 ...

  10. github -- fork提交项目

    我们在进行Github协同开发的时候,往往会去fork一个仓库到自己的Github中,过一段时间以后,原仓库可能会有各种提交以及修改,很可惜,Github本身并没有自动进行同步的机制,这个需要我们手动 ...