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. iframe 父子窗口相互之间调用语法

    一.父窗口调用iframe子窗口方法 1.HTML语法:<iframe name="myFrame" src="child.html"></i ...

  2. MongoDB复制机制实例

    MongoDB的主从复制是一个主可以多从已从又可以为主进行主从复制.在这里就是实现一主一从一个仲裁服务器使用一个数据库服务器通过提供不同的端口. 一.启动一个MongoDB服务名字是applicati ...

  3. Oracle DBLINK 抽数以及DDL、DML操作

    DB :  11.2.0.3.0 原库实例orcl:SQL> select instance_name from v$instance; INSTANCE_NAME--------------- ...

  4. Java Collections Source Code Series 2 ---接口

    废话开篇 自己学完Java Collections框架之后,其中的一个较大的收获就是接口对于层次的重要性.Java Collections的最终实现至少有几十个,其中很多都有非常相似的功能(metho ...

  5. JVM学习总结一——内存模型

    JVM是java知识体系的基石之一,任何一个java程序的运行,都要借助于他.或许对于我这种初级程序员而言,工作中很少有必要刻意去关注JVM,然而如果能对这块知识有所了解,就能够更清晰的明白程序的运行 ...

  6. jira插件带ui界面和几种方式

    http://localhost:2990/jira/plugins/servlet/issuecrud jira插件带ui界面和几种方式 https://developer.atlassian.co ...

  7. mysql 任意连接

    例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话. mysql> GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDE ...

  8. 为什么X86汇编中的mov指令不支持内存到内存的寻址?

    在X86汇编中,MOV [0012H], [0016H]这种指令是不允许的,至少得有一个操作数是寄存器.当然,这种问题在用高级语言的时候看不到,感觉好像基本上都是从内存到内存啊,为毛到了汇编就不行了? ...

  9. 手把手教你自动生成Makefile

    概述:autoconf/automake工具用于自动创建功能完善的Makefile文件,接下来简单介绍一下,如何使用上述工具 自动生成Makefile 前提:安装autoconf工具(ubuntu:s ...

  10. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...