题意:给一个初始值1,每步操作将1替换为01,将0替换为10。问N步操作后有多少对连续的0。

解法:f[i]表示第i步后的答案。可以直接打表发现规律——奇数步后,f[i]=f[i-1]*2-1;偶数步后,f[i]=f[i-1]*2+1;
至于原因——我只能简单说一点。第i步后的答案可由i-1步后的“01”+“1”+“0”的个数推出,而“01”*2+“1”+“0”=01串的总个数。用x表示i-1步后的“01”的个数,则f[i]=x+(2^(i-1)-x*2);但这样复杂度挺高,我也不知道怎么优化了。

noi oj上的实际数据没有1000这么大,在65以内,用long long也可以过。

 1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<iostream>
5 using namespace std;
6 #define N 1010
7
8 int n;
9 long long f[N];
10
11 int main()
12 {
13 f[1]=0;
14 for (int i=2;i<=N;i++)
15 {
16 if (i%2) f[i]=f[i-1]*2-1;
17 else f[i]=f[i-1]*2+1;
18 }
19 while(~scanf("%d",&n)) printf("%lld\n",f[n]);
20 return 0;
21 }

无高精度

我高精度的不知为何在noi oj上AC,在poj上WA。若有大牛能纠正我,请多多指教~

 1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<iostream>
5 using namespace std;
6 #define N 1000
7
8 struct node
9 {
10 int s[210];
11 int l;
12 node() {l=0;memset(s,0,sizeof(s));}
13 };
14 node f[N+10];
15
16 node operator*(node x,int y)//不可省掉构成运算符左右的整型
17 {
18 node z;
19 z.l=x.l;
20 for (int i=1;i<=z.l;i++)
21 {
22 z.s[i]+=x.s[i]*2;
23 if (z.s[i]>9) z.s[i+1]+=z.s[i]/10,z.s[i]%=10;
24 }
25 while (z.s[z.l+1]) z.l++;
26 return z;
27 }
28 node operator-(node x,int y)
29 {
30 node z=x;
31 int t=1;
32 z.s[t]--;
33 while (z.s[t]<0) z.s[t]+=10,z.s[++t]--;
34 while (!z.s[z.l]) z.l--;
35 return z;
36 }
37 node operator+(node x,int y)
38 {
39 node z=x;
40 int t=1;
41 z.s[t]++;
42 while (z.s[t]>9) z.s[t+1]+=z.s[t]/10,z.s[t++]%=10;
43 while (z.s[z.l+1]) z.l++;
44 return z;
45 }
46 void print(node x)
47 {
48 for (int i=x.l;i>=1;i--)
49 printf("%d",x.s[i]);
50 printf("\n");
51 }
52 int main()
53 {
54 freopen("a.in","r",stdin);
55 freopen("a.out","w",stdout);
56 f[1].l=1,f[1].s[1]=0;
57 for (int i=2;i<=N;i++)
58 {
59 if (i%2) f[i]=f[i-1]*2-1;
60 else f[i]=f[i-1]*2+1;
61 }
62 int n;
63 while(~scanf("%d",&n)) print(f[n]);
64 return 0;
65 }

高精度+重载运算符

P.S.重载运算符 不可省掉构成运算符左右的2个类型,例如:整型。

【noi 2.6_9290】&【poj 2680】Computer Transformation(DP+高精度+重载运算符)的更多相关文章

  1. 【noi 2.6_9280】&【bzoj 1089】严格n元树(DP+高精度+重载运算符)

    题意:定义一棵树的所有非叶节点都恰好有n个儿子为严格n元树.问深度为d的严格n元树数目. 解法:f[i]表示深度为<=i的严格n元树数目.f[i]-f[i-1]表示深度为i的严格n元树数目.f[ ...

  2. HOJ 2148&POJ 2680(DP递推,加大数运算)

    Computer Transformation Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4561 Accepted: 17 ...

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

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

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

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

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

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

  6. (大数)Computer Transformation hdu1041

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

  7. POJ.3624 Charm Bracelet(DP 01背包)

    POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...

  8. Computer Transformation(简单数学题+大数)

    H - Computer Transformation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &am ...

  9. POJ 2995 Brackets 区间DP

    POJ 2995 Brackets 区间DP 题意 大意:给你一个字符串,询问这个字符串满足要求的有多少,()和[]都是一个匹配.需要注意的是这里的匹配规则. 解题思路 区间DP,开始自己没想到是区间 ...

随机推荐

  1. Approach for Unsupervised Bug Report Summarization 无监督bug报告汇总方法

    AUSUM: approach for unsupervised bug report summarization 1. Abstract 解决的bug被归类以便未来参考 缺点是还是需要手动的去细读很 ...

  2. 【JDBC核心】JDBC 概述

    JDBC 概述 数据的持久化 持久化(persistence):把数据保存到可掉电式存储设备中以供之后使用.大多数情况下,特别是企业级应用,数据持久化意味着将内存中的数据保存到硬盘上加以"固 ...

  3. Shiro的认证与授权

    shiro实战教程 一.权限管理 1.1什么是权限管理 基本上涉及到用户参与的系统都需要进行权限管理,权限管理属于系统安全的范畴,权限管理实现对用户访问系统的控制,按照安全规则或者安全策略控制用户可以 ...

  4. 【ORA】ORA-00030: User session ID does not exist.

    今天巡检,查询锁相关的情况的时候,确认业务后,准备将锁干掉,但是干掉的时候报了一个错误,ORA-00030 发现回话不存在,我以为pmon进程已经将锁进程kill掉了,就再次查看,发现,还是存在 这个 ...

  5. CTFshow萌新赛-萌新福利

    下载链接文件 拿到show.bin文件 使用010Editor工具打开文件 做取反操作 取反后可以看到 把show.bin改为show.m4a 使用音频播放软件播放,即可得到flag

  6. SAP内表类型及其数据读取效率评估

    内表大概分3种: 1.标准表standard tables:如果不指定BINARY SEARCH附加选项,则默认为线性查找(linear search),既一条一条的查找. 2.排序表(sorted ...

  7. php 换行符

    PHP 中换行可以用 PHP_EOL 来替代,以提高代码的源代码级可移植性: unix系列用 \n windows系列用 \r\n mac用 \r 总结:在一些大文本域中换行的文本可以用这个来进行切割 ...

  8. 使用npm install安装项目依赖的时候报错

    使用npm install安装项目依赖的时候报错: npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@4.14.1 postin ...

  9. Oracle 常用命令大全(持续更新)

    数据库 ----数据库启动 & 关闭 启动数据库 SQL> startup nomount; SQL> alter database mount; SQL> alter da ...

  10. Crunch

    Crunch 目录 1. 简介 2. 命令格式 3. options可选参数 3.1 -b number[type] 3.2 -c number 3.3 -d numbersymbol 3.4 -e ...