UVA 1647 Computer Transformation
https://vjudge.net/problem/UVA-1647
题意:
开始有一个1,接下来每一步1变成01,0变成10
问n不之后00的个数
打表找规律
第3步之后:
如果第i步之后有x个字符,
那么第i+1步之后 的后x个字符与第i步一样
前x个字符是第i步取反
所以00得个数由三部分组成
1、上一步00的个数
2、上一步11的个数
3、当i为偶数时,前x个字符的最后一个是0,后x个字符的第一个是0,00个数+1
f[i][0]=f[i-1][0]+f[i-1][1]+!(i&1)
f[i][1]=f[i-1][0]+f[i-1][1]
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct BigInteger
{
int len;
int num[];
BigInteger() { len=; memset(num,,sizeof(num));}
BigInteger operator + (BigInteger p) const
{
BigInteger b;
b.len=max(len,p.len);
int x=max(len,p.len);
for(int i=;i<=x;i++)
{
b.num[i]+=num[i]+p.num[i];
b.num[i+]=b.num[i]/;
b.num[i]%=;
}
if(b.num[x+]) x++;
b.len=x;
return b;
}
void operator = (BigInteger p)
{
this->len=p.len;
for(int i=;i<=len;i++) this->num[i]=p.num[i];
}
void print()
{
for(int i=len;i;i--) printf("%d",num[i]);
printf("\n");
}
};
BigInteger f[][];
BigInteger e;
int main()
{
f[][].len=;
f[][].num[]=;
f[][].len=;
f[][].num[]=;
e.len=;
e.num[]=;
for(int i=;i<=;i++)
{
f[i][]=f[i-][]+f[i-][];
if(i&) f[i][]=f[i-][]+f[i-][];
else f[i][]=f[i-][]+f[i-][]+e;
}
int n;
while(scanf("%d",&n)!=EOF) f[n][].print();
}
UVA 1647 Computer Transformation的更多相关文章
- UVA - 1647 Computer Transformation(计算机变换)(找规律)
题意:初始串为一个1,每一步会将每个0改成10,每个1改成01,因此1会依次变成01,1001,01101001,……输入n(n<=1000),统计n步之后得到的串中,"00" ...
- HDU 1041 Computer Transformation (简单大数)
Computer Transformation http://acm.hdu.edu.cn/showproblem.php?pid=1041 Problem Description A sequenc ...
- Computer Transformation(规律,大数打表)
Computer Transformation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- hdu_1041(Computer Transformation) 大数加法模板+找规律
Computer Transformation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- (大数)Computer Transformation hdu1041
Computer Transformation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- Computer Transformation(简单数学题+大数)
H - Computer Transformation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &am ...
- UVa 1647 (递推) Computer Transformation
题意: 有一个01串,每一步都会将所有的0变为10,将所有的1变为01,串最开始为1. 求第n步之后,00的个数 分析: 刚开始想的时候还是比较乱的,我还纠结了一下000中算是有1个00还是2个00 ...
- Computer Transformation(hdoj 1041)
Problem Description A sequence consisting of one digit, the number 1 is initially written into a com ...
- ACM学习历程—HDU1041 Computer Transformation(递推 && 大数)
Description A sequence consisting of one digit, the number 1 is initially written into a computer. A ...
随机推荐
- FivePlus——团队展示
光耀101 <光耀101>是福州大学数计学院计算机专业推出的中国首部程序猿脱发养成节目.由张栋担任发起人,刘晨瑶.畅畅担任导师. 该节目召集了你猜多少位选手,通过任务.训练.考核,让选 ...
- HDU 5855 Less Time, More profit 最大权闭合子图
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5855 Less Time, More profit Time Limit: 2000/1000 MS ...
- CodeForces 479C Exams 贪心
题目: C. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- StringBuilder、StringBuffer和String三者的联系和区别
String 类 String的值是不可变的,这就导致每次对String的操作都会生成新的String对象,不仅效率低下,而且大量浪费有限的内存空间. String a = "a ...
- lintcode-384-最长无重复字符的子串
384-最长无重复字符的子串 给定一个字符串,请找出其中无重复字符的最长子字符串. 样例 例如,在"abcabcbb"中,其无重复字符的最长子字符串是"abc" ...
- lintcode-223-回文链表
223-回文链表 设计一种方式检查一个链表是否为回文链表. 样例 1->2->1 就是一个回文链表. 挑战 O(n)的时间和O(1)的额外空间. 标签 链表 思路 找到链表中点后,翻转链表 ...
- 在本地数据库目录或系统数据库目录中已经存在数据库别名""的解决办法
在创建数据库时遇到数据库别名已存在的问题时,可以: 1. 首先用 db2 list database directory 命令看在系统数据库目录(System Database Directory)中 ...
- 三层神经网络自编码算法推导和MATLAB实现 (转载)
转载自:http://www.cnblogs.com/tornadomeet/archive/2013/03/20/2970724.html 前言: 现在来进入sparse autoencoder的一 ...
- Q3 大型科技公司季报
1. alphabet Alphabet(谷歌母公司)今天发布了截至9月30日的2018财年第三季度财报.报告显示,Alphabet第三季度总营收为337.40亿美元,比上年同期的277.72亿美元增 ...
- RAID卡服务器安装2003教程
这里先讲讲安装系统的几个思路: 1.U盘安装法(U盘只做可启动PE,常用的大白菜,IT天空,老毛桃.....拷贝系统ISO镜像到U盘,进入PE之后找到ISO,用虚拟光驱加载,运行WIN系统安装器 ...