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. CodeForces 569A 第八次比赛 C题

    Description Little Lesha loves listening to music via his smartphone. But the smartphone doesn't hav ...

  2. Android--Fragment的懒加载

    我们都知道,fragment放在viewPager里面,viewpager会帮我们预先加载一个,但是当我们要看fragment里面的内容时,我们也许只会去看第一个,不会去看第二个,如果这时候不去实现f ...

  3. hdu 2988 Dark roads

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2988 Dark roads Description Economic times these days ...

  4. Java求职面试准备之常见算法

    最近在求职面试,整理一下常见面试算法: 对TestAlgorithms.java中方法的测试见JunitTestAlgorithms.java(引入了junit4) 1.TestAlgorithms. ...

  5. Java使用JSP Tag Files & JSP EL Functions打造你自己的页面模板

    1. 简单说明:在JSP 2.0后, 你不再需要大刀阔斧地定义一堆TagSupport或BodyTagSupport, 使用JSP Tag Files技术可以实现功能强大的页面模板技术. 在这里抛砖引 ...

  6. 硬件描述语言Verilog设计经验总结

    一.硬件描述语言Verilog 粗略地看Verilog与C语言有许多相似之处.分号用于结束每个语句,注释符也是相同的(/* ... */和// 都是熟悉的),运算符"=="也用来测 ...

  7. 关于sqlserver身份登录失败的解决方法

    前几天写程序需要用到数据库,下载了一个用用,出现了不少的小问题(都怪我的32bit不争气的笔记本),有问题不要怕,至少证明我们在思考解决方案.废话不说了,直接上正题. Sqlserver有两种登陆方式 ...

  8. boostrap中lg,md,sm,xs

    boostrap中lg,md,sm,xs分别表示多少px? .col-xs- 超小屏幕 手机 (<768px).col-sm- 小屏幕 平板 (≥768px).col-md- 中等屏幕 桌面显示 ...

  9. quartz2D简单使用

    quartz2D绘图 1:上下文:context,这个翻译不好理解,其实翻译环境更好一点,就是给了你一个画板,你看不到而已 在: CGContextRef ctx = UIGraphicsGetCur ...

  10. Node.js 学习(六)Node.js EventEmitter

    Node.js 所有的异步 I/O 操作在完成时都会发送一个事件到事件队列. Node.js里面的许多对象都会分发事件:一个net.Server对象会在每次有新连接时分发一个事件, 一个fs.read ...