题意:

给原始序列1

给定变化规则是,对于原来的序列每一个0前边插入1,每个1前边插入0.

问原始序列经过n次变化之后有多少对相邻的0.

规律题:

从第二次开始

当第奇数次变化之后,数量变成原来数量的两倍-1;

当第偶数次变化之后,数量变成原来数量的两倍+1;

但是由于数据2^1000次方太大,需要用到大数,屌丝还没学到java对大数的处理,所以只写了一个高精度。

/*************************************************************************
> File Name: C.cpp
> Author: ttpond
> Created Time: 2015-8-22 15:32:30
************************************************************************/
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
using namespace std;
char dp[][];
void cal(int pos)
{
int len=strlen(dp[pos-]);
int mm[];
memset(mm,,sizeof(mm));
int tmp;
for(int i=;i<len;i++)
{
mm[i]+=(dp[pos-][i]-)*;
mm[i+]+=mm[i]/;
mm[i]=mm[i]%;
}
for(int i=;i<len+;i++)
{
dp[pos][i]=mm[i]+;
}
if(dp[pos][len]=='')
dp[pos][len]=;
}
void add(int pos)
{
int len=strlen(dp[pos]);
int tmp;
int mm[];
memset(mm,,sizeof(mm));
mm[]=;
for(int i=;i<len;i++)
{
mm[i]+=dp[pos][i]-;
mm[i+]=mm[i]/;
mm[i]=mm[i]%;
}
for(int i=;i<len+;i++)
{
dp[pos][i]=mm[i]+;
}
if(dp[pos][len]=='')
dp[pos][len]=;
}
void sub(int pos)
{
int len=strlen(dp[pos]);
int mm[];
memset(mm,,sizeof(mm));
mm[]=-;
for(int i=;i<len;i++)
{
mm[i]+=dp[pos][i]-;
if(mm[i]<)
{
mm[i]+=;
mm[i+]--;
}
}
for(int i=;i<len;i++)
{
dp[pos][i]=mm[i]+;
}
if(dp[pos][len-]=='')
dp[pos][len-]=;
}
int main()
{
memset(dp,,sizeof(dp));
dp[][]='';
dp[][]='';
dp[][]='';
bool st=;
for(int i=;i<=;i++)
{
cal(i);
if(!st)
{
add(i);
}
else
{
sub(i);
}
st=!st;
}
int n;
while(scanf("%d",&n)!=EOF)
{
int len=strlen(dp[n]);
for(int i=len-;i>=;i--)
{
printf("%c",dp[n][i]);
}
printf("\n");
}
}

HDU 1041的更多相关文章

  1. HDU 1041 Computer Transformation (简单大数)

    Computer Transformation http://acm.hdu.edu.cn/showproblem.php?pid=1041 Problem Description A sequenc ...

  2. hdu 1041 (OO approach, private constructor to prevent instantiation, sprintf) 分类: hdoj 2015-06-17 15:57 25人阅读 评论(0) 收藏

    a problem where OO seems more natural to me, implementing a utility class not instantiable. how to p ...

  3. HDU 1041 Computer Transformation

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

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

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

  5. HDU 1041(01展开 大数)

    题意是将 1 展开成 01 ,将 0 展开成 10 ,问这样展开 n 次后序列中有多少对 0. 手写发现:0,1,1,3,5,11 ... 即 a[ i ] = a[ i -1 ] + a[ i - ...

  6. hdu 1041(递推,大数)

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

  7. HDU 1041 Computer Transformation 数学DP题解

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

  8. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  9. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

随机推荐

  1. cluvfy comp命令用法

    1.获取集群验证工具cluvfy的帮助信息 grid@rac1:/home/grid>cluvfy -help USAGE: cluvfy [ -help ] cluvfy stage { -l ...

  2. pickle 两个使用小方法

    def pickle_load(file_path): f = open(file_path,'r+') data = pickle.load(f) f.close() return data     ...

  3. Gym - 100676G Training Camp (状压dp)

    G. Training Camp[ Color: Yellow ]Montaser is planning to train very hard for ACM JCPC 2015; he has p ...

  4. dirname, basename - 分析路径成员

    总览 (SYNOPSIS) #include <libgen.h> char *dirname(char *path); char *basename(char *path); 描述 (D ...

  5. 字符串 || CodeForces 591B Rebranding

    给一字符串,每次操作把字符串中的两种字母交换,问最后交换完的字符串是多少 arr数组记录每个字母最后被替换成了哪个字母 读入字符前面加一空格 scanf(" %c %c", &am ...

  6. [BZOJ2120]:数颜色(分块?)

    题目传送门 我感觉这种题没必要扯淡题目大意了,没啥用. 暴力过掉,擦了个边. 主要是讲一下这道题我用到的卡常. 首先,0,1标记我用的位运算,位运算符跑的要比正常的+,-,×,÷,true,false ...

  7. 总结Java开发者经常会犯的前十种错误

    [导读] 在Java中,有些事物如果不了解的话,很容易就会用错,如数组转换为数组列表.元素删除.Hashtable和HashMap.ArrayList和LinkedList.Super和Sub构造函数 ...

  8. luogu P1364 医院设置

    题目描述 设有一棵二叉树,如图: 其中,圈中的数字表示结点中居民的人口.圈边上数字表示结点编号,现在要求在某个结点上建立一个医院,使所有居民所走的路程之和为最小,同时约定,相邻接点之间的距离为1.如上 ...

  9. 编写一个微信小程序

    1.创建项目 2.创建目录及文件,结构如下:

  10. ubuntu14.04 configure: error: xml2-config not found. Please check your libxml2 installation错误解决

    今天在ubuntu14.04上安装php7时 执行:./configure命令时 一直报configure: error: xml2-config not found. Please check yo ...