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 ...
随机推荐
- EBP的妙用[无法使用ESP定律时]
1.了解EBP寄存器 在寄存器里面有很多寄存器虽然他们的功能和使用没有任何的区别,但是在长期的编程和使用 中,在程序员习惯中已经默认的给每个寄存器赋上了特殊的含义,比如:EAX一般用来做返回值,ECX ...
- 【WCF--初入江湖】11 安全
11 安全 前言 [1]传输安全 传输安全模式 传输安全与绑定协议 [2]身份验证 身份验证分类 证书 示例:传输安全匿名客户端证书的使用 1. 传输安全 保证信息在传输过程中的 ...
- Opc
http://www.tuicool.com/articles/nymUz2 http://blog.chinaunix.net/uid-20692368-id-3434001.html http:/ ...
- php获取数组长度的方法(有实例)
php获取数组长度的方法,php为我们提供了两个函数可以计算一维数组长度,如count,sizeof都可以直接统计数组长度,还有获取二维数组的方法. 在php中获取数组长度方法很简单,php为我们提供 ...
- C Primer Plus 第4章 字符串和格式化输入/输出 编程练习
1. #include <stdio.h> int main(void) { ]; ]; printf("请输入您的名字: "); scanf("%s&quo ...
- Project Euler 80:Square root digital expansion 平方根数字展开
Square root digital expansion It is well known that if the square root of a natural number is not an ...
- 【nginx运维基础(7)】常用PHP开源程序的NginxRewrite示例
在写伪静态的时候,可以先用一个打印$_GET的PHP文件来测试,并且一定注意浏览器缓存,另外正则里如果有"{}",正则要用双引号包起来 dedecms location / { r ...
- SQLite操作(C# )
C#连接SQLite的...方法 http://www.cnblogs.com/virusswb/archive/2010/09/17/SQLite1.html 1 SQLite简介 SQLite,是 ...
- Android:密码显示隐藏
效果: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= ...
- C#基础练习(使用委托窗体传值)
主界面: Form1中的代码: namespace _06委托练习_窗体传值 { public partial class Form1 : Form { public ...