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. Hive 脚本执行

    hive执行脚本 hive -e “sql语句” 会将查询的结果打印在控制台上.  hive -e “sql语句” >> xxx 会将查询的结果重定向到xxx文件中,会显示OK和抓取的数据 ...

  2. http接口测试—自动化测试框架设计

    转载:https://my.oschina.net/hellotest/blog/499719 一.测试需求描述 对服务后台一系列的http接口功能测试. 输入:根据接口描述构造不同的参数输入值(Js ...

  3. 使用JMeter录制手机App脚本

    Apache JMeter是100%的Java桌面应用程序,用于对软件做压力测试.它最初被设计用于Web应用测试,但后来扩展到其他测试领域.现如今这款软件越来越受到测试人员的青睐,相比于LoadRun ...

  4. 原来,多年以来,我一直是个curl/CRUD程序员

    curl,就是create,update,remove,list的首字母简写.说是CRUD似乎更流行些,不过无所谓,知道是一个意思就好. curl程序员,就是增改删查程序员,中文说增删改查更加顺口. ...

  5. Windows / Linux 一件编译zlib库

    一. 下载zlib库 : http://www.zlib.net 本文以  zlib-.tar.xz  为例 二. 解压文件得到 zlib- 文件夹,修改 zlib-/CMakeLists.txt 文 ...

  6. Java 分支结构 - if...else/switch

    Java 分支结构 - if...else/switch 顺序结构只能顺序执行,不能进行判断和选择,因此需要分支结构. Java 有两种分支结构: if 语句 switch 语句 if 语句 一个 i ...

  7. react-native 常用组件的用法(一)

    1.View组件 View是一个支持Flexbox布局.样式.一些触摸处理.和一些无障碍功能的容器,并且它可以放到其它的视图里,也可以有任意多个任意类型的子视图. View的设计初衷是和StyleSh ...

  8. 超高逼格Log日志打印

    代码地址如下:http://www.demodashi.com/demo/12646.html 前言 Log日志的打印一直是一个比较头疼的事,怎样才能让自己的log显示更多信息,怎样才能让自己的log ...

  9. 使用lua扩展应用程序

    全局变量的操作 void lua_getglobal(lua_State * L ,const char * name) 此函数从lua中取出一个名为name的全局变量并将其压入栈中. 如当lua文件 ...

  10. 数据结构之shell排序

    #SIZE  10        //直接插入排序     void insert_sort(){           int i,j;           int array[SIZE+1];   ...