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. SharePoint 项目的死法(一)

    SharePoint是Microsoft的一个巨NB的产品, 从可查到的数据来看, 财富500强中已经有超过80%的企业已经使用了SharePoint的不同版本,从项目实施的经验来看, 个人感觉这个数 ...

  2. Android-简单的sdcard文件浏览

    功能:能够浏览手机里面的文件夹和文件,代码灰常简单 先看布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/r ...

  3. Oracle用户密码过期问题解决

    一.用户密码即将过期,导致autotrace无法打开           如果用户密码即将过期,在登录数据库时会收到如下提示:           ERROR:            ORA-2800 ...

  4. iOS-CALayer

    iOS开发UI篇—CAlayer层的属性 一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property ...

  5. c/c++常用代码---doc,ppt,xls文件格式转PDF格式[转]

    [转]doc,ppt,xls文件格式转PDF格式 http://blog.csdn.net/lee353086/article/details/7920355 确实好用. 需要注意的是#import文 ...

  6. Python实现C4.5(信息增益率)

    Python实现C4.5(信息增益率) 运行环境 Pyhton3 treePlotter模块(画图所需,不画图可不必) matplotlib(如果使用上面的模块必须) 计算过程 st=>star ...

  7. 微软职位内部推荐-Senior Software Engineer-SDP

    微软近期Open的职位: Position: Senior SDE The R&D of Shared Data Platform at Application and Services Gr ...

  8. iTween

    http://u3d.as/content/pixelplacement/i-tween/1s9 download http://itween.pixelplacement.com/documenta ...

  9. 阿里云服务器Node环境配置

    最近,将网站的阿里云服务器迁移到阿里云北京机房,记录下CentOS的迁移过程. 首次登录云服务器,要先进行用户设置. 用户设置 首先用passwd命令修改超级管理员root密码. $ passwd 根 ...

  10. RegExp.exec和String.match深入理解

    今天在重新阅读<JavaScript权威指南>的RegExp和String的时候,看到了2个比较容易混淆的函数:RegExp的exec和String的match 这2个函数都是从指定的字符 ...