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. ISP基础一

    1.专业术语 [ColorTemp] 色温 所谓色温,简而言之,就是定量地以开尔文温度(K)来表示色彩.英国著名物理学家开尔文认为,假定某一黑体物质,能够将落在其上的所有热量吸收,而没有损失,同时又能 ...

  2. consist of, made up of

    consist vi.由……组成:由……构成(常和介词of构成固定搭配)made up of由……组成[例如] One year consists of 365 days.一年有365天.The te ...

  3. leetcode题解:Search for a Range (已排序数组范围查找)

    题目: Given a sorted array of integers, find the starting and ending position of a given target value. ...

  4. java学习笔记——日期处理

    获取系统当前时间使用:java.util.Date类,而这个Date的构造方法如下: 无参构造:public Date() 有参构造:public Date(long date) 第一个实例: imp ...

  5. 【VBA】查看当前窗口的宽与高

    打开的Excle如何使用VBA查看当前窗口的宽与高呢?代码如下: Sub 查看宽度与高度() Dim myWidth As Double Dim myHeigth As Double myWidth ...

  6. 补充——a.extend(b) #合并列表——a.update(b) #把b字典的元素加入到a字典里面

    1.list dict tulpe a='dongtian'a[0]='h' #会报错,字符串不能修改print(a) a=[]a.append('abc')a.insert(0,'vcc') b=[ ...

  7. Android下Slidingmenu和actionbarsherlock的使用

    1 http://blog.csdn.net/wangjinyu501/article/details/9331749  博客很多,推荐此教程,slidingmenu的demo可以演示 2 http: ...

  8. js事件之onmousedown和onmouseup

    <!DOCTYPE html> <html> <head> <script> function mouseDown() { document.getEl ...

  9. java之JDK动态代理

    © 版权声明:本文为博主原创文章,转载请注明出处 JDK动态代理: JDK动态代理就是在程序运行期间,根据java的反射机制自动的帮我们生成相应的代理类 优势: - 1. 业务类只需要关注业务逻辑本身 ...

  10. JavaScript的split()

    JavaScript split() 方法 JavaScript String 对象 定义和用法 split() 方法用于把一个字符串分割成字符串数组. 语法 stringObject.split(s ...