HDU 1041 Computer Transformation
这道题目的意思是:一开始有一个数字 1 ,在接下来的时间中,计算机会按照如下规则进行扩展:
0 –> 1 0
1 –> 0 1
求n秒之后,有多少对相邻的0。 例如1 0 0 1有 1 对相邻的0.
这道题目是一道规律题,可以直接例举前面的数据得到规律:
0 0 1 1 3 5 11 21 43 85
通过例举的数据可以很明显的看出,从第 1s 开始,如果是偶数秒,那么b[ i ] = b[ i – 1 ] * 2 – 1,而奇数秒则是b[ i ] = b[ i – 1 ] * 2 + 1。于是可以预处理打表得出0 ~ 1000的结果。
需要注意的是,这道题需要用到高精度,因为最大的值约为 2 ^ 1000,这个数非常大。
附AC代码:
1: #include <iostream>
2: #include <string>
3: #include <algorithm>
4: using namespace std;
5:
6: int s[1005][505];
7: int num, temp = 0;
8:
9: int main()
10: {
11: s[0][1] = 0;
12: s[1][1] = 0;
13: s[2][1] = 1;
14: s[3][1] = 1;
15: for(int i = 4; i <= 1000; ++i)
16: {
17: for(int j = 1; j <= 500; ++j)
18: {
19: s[i][j] = s[i - 1][j] + 2 * s[i - 2][j] + temp;
20: temp = s[i][j] / 10;
21: s[i][j] %= 10;
22: }
23: }
24: while(~scanf("%d", &num))
25: {
26: if(num == 1)
27: puts("0");
28: else
29: {
30: int i;
31: for(i = 500; i > 0; --i)
32: if(s[num][i] != 0)
33: break;
34: for(int j = i; j >= 1; --j)
35: printf("%d", s[num][j]);
36: puts("");
37: }
38: }
39: return 0;
40: }
HDU 1041 Computer Transformation的更多相关文章
- HDU 1041 Computer Transformation (简单大数)
Computer Transformation http://acm.hdu.edu.cn/showproblem.php?pid=1041 Problem Description A sequenc ...
- HDU 1041 Computer Transformation(找规律加大数乘)
主要还是找规律,然后大数相乘 #include<stdio.h> #include<string.h> #include<math.h> #include<t ...
- HDU 1041 Computer Transformation 数学DP题解
本题假设编程是使用DP思想直接打表就能够了. 假设是找规律就须要数学思维了. 规律就是看这些连续的0是从哪里来的. 我找到的规律是:1经过两次裂变之后就会产生一个00: 00经过两次裂变之后也会产生新 ...
- Computer Transformation(规律,大数打表)
Computer Transformation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- hdu 3695 Computer Virus on Planet Pandora(AC自己主动机)
题目连接:hdu 3695 Computer Virus on Planet Pandora 题目大意:给定一些病毒串,要求推断说给定串中包括几个病毒串,包括反转. 解题思路:将给定的字符串展开,然后 ...
- 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/ ...
- hdu 1041(递推,大数)
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 ...
随机推荐
- WCF 基础
ServiceModel 配置元素 Binding 配置元素: 客户端Web.config: <?xml version="1.0" encoding="utf-8 ...
- .bash_profile备份
# ~/.bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User sp ...
- String.IsNullOrEmpty()和String.IsNullOrWhiteSpace()
转自:http://hi.baidu.com/saclrpqmttbntyq/item/4592fc72c5a19e5c0d0a07eb 由于总用 String.IsNullOrEmpty( s ) ...
- [转载]Spring Beans Auto-Wiring
Autowiring Modes You have learnt how to declare beans using the <bean> element and inject < ...
- MSVC CRT运行库启动代码分析
原文链接:http://www.programlife.net/msvc-crt-startup.html 在程序进入main/WinMain函数之前,需要先进行C运行库的初始化操作,通过在Visua ...
- 核稀疏表示分类(KSRC)
参考:<Kernel SparseRepresention-Based Classifier> 原文地址:http://www.cnblogs.com/Rosanna/p/3372153. ...
- spring aop通过joinpoint传递参数
三.总结. 我们可以通过Advice中添加一个JoinPoint参数,这个值会由spring自动传入,从JoinPoint中可以取得. 三.总结. 我们可以通过Advice中添加一个JoinPoint ...
- Linux文件系统介绍
1.ext2/ext3(日志功能)文件系统(Linux标准文件系统.一种索引式文件系统) SuperBlock:Superblock是记录整个filesystem 相关信息的地方,没有Superblo ...
- Linux基础--分类与合并命令
1.sortsort命令将许多不同的域按不同的顺序分类,sort命令的一般格式为: sort -cmu -o output_file [other options] +pos1 +pos2 input ...
- Java学习笔记之:java运算符
一.介绍 计算机的最基本用途之一就是执行数学运算,作为一门计算机语言,Java也提供了一套丰富的运算符来操纵变量.我们可以把运算符分成以下几组: 算术运算符 关系运算符 位运算符 逻辑运算符 赋值运算 ...