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. 记录一次ceph recovery经历

    一次ceph recovery经历 背景 这是一个測试环境. 该环境中是cephfs 一共12个节点, 2个client.2个mds.8个osd mds: 2颗CPU,每一个4核.一共是8核. 128 ...

  2. SparkMLlib聚类学习之KMeans聚类

    SparkMLlib聚类学习之KMeans聚类 (一),KMeans聚类 k均值算法的计算过程非常直观: 1.从D中随机取k个元素,作为k个簇的各自的中心. 2.分别计算剩下的元素到k个簇中心的相异度 ...

  3. shell中declare命令

    declare命令有如下选项: -a 声明一个数组 -i 声明一个整型 -f 打印所有函数定义 -F 仅打印函数名字 -r 声明一个readonly变量,该变量的值无法改变,并且不能为unset -x ...

  4. 自己定义控件-LinearListView

    一.描写叙述 用LinearLayout 实现的一个ListView ,重写了ListView中的经常使用函数,所以使用起来和ListView 没有区别. 比方:setAdapter.addHeade ...

  5. POJ 2388:Who&#39;s in the Middle

    Who's in the Middle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31015   Accepted: 1 ...

  6. react-native fetch 请求封装

    1.fetch 函数封装 fetch.js /** * 请求头 * @type {{Accept: string, Content-Type: string}} */ const header = { ...

  7. TCP/IP详解 卷一(第二十章 TCP的成块数据流)

    本章将介绍TCP所使用的被称为滑动窗口协议的一种流量控制方法. 该协议允许发送方在停止并等待确认前可以连续发送多个分组,这样就可以加速数据的传输. 滑动窗口 下图用可视化的方法显示了滑动窗口协议 我们 ...

  8. hdu 神、上帝以及老天爷 java

    问题: 递推.可是a[i]=(a[i-1]+a[i-2])+(i-1)公式没有推出来. 在递推时,for循环约束值用的输入的m导致数组没有储存数. 在算阶乘时for循环中将i和j用混了,导致没有数输出 ...

  9. Eclipse配置总结

       按照公司要求,开发环境使用Eclipse Juno版本,需要安装maven插件和RTC插件.      经过一下午的尝试,总结经验教训:        1.eclipse安装maven的m2ec ...

  10. Win7 64bit+Anaconda(3-5.0.1,Python3.6)+Pycharm(community-2017.3.3)+OpenCV(python‑3.4.0‑cp36‑cp36m)(转载)

    Anaconda(3-5.0.1,Python3.6)下载链接:https://pan.baidu.com/s/1bqFwLMB 密码:37ih Pycharm(community-2017.3.3) ...