H - Computer Transformation

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status Practice _

Appoint description: 
System Crawler  (Oct 10, 2016 1:02:59 PM)

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

//这题意思是

1 01        0

2 1001       1

3 01101001    1

1->01 0->10

就这么一直变下去,问 n 步之后,有多少个相邻的 0

我是先输出模拟了大概 8 项找出了规律,然后。。。wa

因为数据太大,long long 也存不下

然后用字符串,当做大数处理,就可以了,注意一些细节问题,代码里有

 /*
//EEE
#include <stdio.h>
#include <string.h> char ch[10][1200]; int main()
{
strcpy(ch[0],"01"); for (int i=1;i<10;i++)
{
int k=0;
int len=strlen(ch[i-1]);
for (int j=0;j<len;j++)
{
if (ch[i-1][j]=='0')
{
ch[i][k++]='1';
ch[i][k++]='0';
}
else
{
ch[i][k++]='0';
ch[i][k++]='1';
}
}
ch[i][k]='\0';
}
for (int i=0;i<10;i++)
{ int sum=0;
int len =strlen(ch[i]);
for (int j=0;j<len-1;j++)
{
if (ch[i][j]=='0'&&ch[i][j+1]=='0')
sum++;
}
//printf("%s\n",ch[i]);
printf("%d\n",sum);
}
return 0;
}
*/ #include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std; char num[][];
char str[]; char *add(char s[])
{
memset(str,,sizeof(str)); int i;
int len=strlen(s);
for (i=;i<len;i++)
s[i]-='';
reverse(s,s+len); for (i=;i<len;i++)
{
str[i]+=s[i]*;
if (i==) str[i]++; if (str[i]>=)
{
str[i]-=;
str[i+]++;
} }
while (str[i]!=) i++;
str[i]='\0';
for (int j=;j<i;j++) str[j]+='';
for (int j=;j<len;j++) s[j]+='';
reverse(str,str+i);
reverse(s,s+len);
return str;
} char *de(char s[])
{
memset(str,,sizeof(str)); int i;
int len=strlen(s);
for (i=;i<len;i++)
s[i]-='';
reverse(s,s+len); int k=,flag=;
for (i=;i<len;i++)
{
str[i]+=s[i]*;
if (str[i]>=)
{
str[i]-=;
str[i+]++;
} if (flag==&&str[i]==)//减1,看这个数最后有几个 0
{
k++;
}
if (str[i]!=) flag=; }
while (str[i]!=) i++;
str[i]='\0'; str[k]--;
while (k--) str[k]=;//减 1 for (int j=;j<i;j++) str[j]+='';
for (int j=;j<len;j++) s[j]+='';
reverse(str,str+i);
reverse(s,s+len);
return str;
} int main()
{
int n;
int i;
int xx=; strcpy(num[],""); for (i=;i<=;i++)
{
if (i%==)
{
add(num[i-]);
strcpy(num[i],str);
} else
{
de(num[i-]);
strcpy(num[i],str);
}
}
while (scanf("%d",&n)!=EOF)
{
printf("%s\n",num[n]);
}
return ;
}

Computer Transformation(简单数学题+大数)的更多相关文章

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

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

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

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

  3. (大数)Computer Transformation hdu1041

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

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

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

  5. HDU 6467 简单数学题 【递推公式 && O(1)优化乘法】(广东工业大学第十四届程序设计竞赛)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6467 简单数学题 Time Limit: 4000/2000 MS (Java/Others)    M ...

  6. HDU 6467.简单数学题-数学题 (“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛)

    简单数学题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  7. Discrete Function(简单数学题)

    Discrete Function There is a discrete function. It is specified for integer arguments from 1 to N (2 ...

  8. JZOJ 5773. 【NOIP2008模拟】简单数学题

    5773. [NOIP2008模拟]简单数学题 (File IO): input:math.in output:math.out Time Limits: 1000 ms  Memory Limits ...

  9. [JZOJ5773]【NOIP2008模拟】简单数学题

    Description       话说, 小X是个数学大佬,他喜欢做数学题.有一天,小X想考一考小Y.他问了小Y一道数学题.题目如下:      对于一个正整数N,存在一个正整数T(0<T&l ...

随机推荐

  1. Makefile学习之通配符和自动变量

    规则中的通配符 “*” ,“?” ,“ [...]”, " % " , " wildcard " 1.“*”  *.c表示所有后缀为.C的文件: 如果文件中用到 ...

  2. BAT文件使程序具有以系统权限运行的效果

    @echo off if "%1" == "h" goto begin mshta vbscript:createobject("wscript.sh ...

  3. 报错kernel:NMI watchdog: BUG: soft lockup - CPU#0 stuck for 26s

    近期在服务器跑大量高负载程序,造成cpu soft lockup.如果确认不是软件的问题. 解决办法: #追加到配置文件中 echo 30 > /proc/sys/kernel/watchdog ...

  4. Unity3d / 3ds max 模型分享站点

    http://www.cgrealm.org/model/ 王国3D模型库 http://www.cgjoy.com/ 游戏特效论坛

  5. window命令

    查看端口占用命令: 开始--运行--cmd 进入命令提示符 输入netstat -aon 即可看到所有连接的PID 之后在任务管理器中找到这个PID所对应的程序如果任务管理器中没有PID这一项,可以在 ...

  6. P6 EPPM 安装和配置指南

    In This Section Installation and Configuration Guide Manual Installation Guides P6 Professional Inst ...

  7. Json,String,Map之间的转换

    前提是String的格式是map或json类型的 String 转Json JSONObject  jasonObject = JSONObject.fromObject(str); String 转 ...

  8. HTML5 Canvas 画钟表

    画钟表是2D画图的老生常谈,我也不能免俗弄了一个.代码如下: <!DOCTYPE html> <html lang="utf-8"> <meta ht ...

  9. 《大话操作系统——做坚实的project实践派》(3)

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbG1ub3M=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...

  10. Android SqliteOpenHelper详解

    一. SQLite介绍 SQLite是android内置的一个很小的关系型数据库. SQLite的官网是http://www.sqlite.org/,可以去下载一些文档或相关信息. 博客中有一篇有稍微 ...