ZOJ - 1633 Big String
来源:互联网 发布:调度流程的优化的意义 编辑:程序博客网 时间:2024/06/06 04:01
Description
We will construct an infinitely long string from two short strings: A = "^__^" (four characters), and B = "T.T" (three characters). Repeat the following steps:
- Concatenate A after B to obtain a new string C. For example, if A = "^__^" and B = "T.T", then C = BA = "T.T^__^".
- Let A = B, B = C -- as the example above A = "T.T", B = "T.T^__^".
Input
The input contains multiple test cases, each contains only one integer N (1 <= N <= 2^63 - 1). Proceed to the end of file.
Output
For each test case, print one character on each line, which is the N-th (index begins with 1) character of this infinite string.
Sample Input
1248
Sample Output
T.^T
分析:本题的规律很明显,第三个串由前两个串拼接,这和非波拉其数列的定义一致,所以我们可以先求出串长的非波拉其数列,存放在数组中,然后求解每组数据;由于当前串是前两个串拼接而来,对于给定的n,可以找到大于n的最小的串长,那么n一定在前两个串中,假设紧邻的三个串分别是A,B,C,当前n在C中,由于n大于B,所以n一定在A中,由题意,A在B后,所以n-len(B)即在A中的位置,如此循环直到n小于7.
#include <cstdio>using namespace std;const int maxn = 1000000;const char* str = "T.T^__^";typedef long long LL;LL fibo[maxn];int main(){LL n;fibo[0] = 4; fibo[1] = 3;for(int i=2; i<maxn; i++) {fibo[i] = fibo[i-1] + fibo[i-2];}while(~scanf("%llu",&n)) {while(n>7) {int i = 0;while(i<maxn && fibo[i]<n) i++;n -= fibo[i-1];}printf("%c\n", str[n-1]);} return 0;}
1 0
- zoj 1633 Big String
- ZOJ - 1633 Big String
- ZOJ 1633 Big String(模拟构造)
- ZOJ 1633 big string
- zoj 2571 Big String Outspread
- ZOJ 2571 Big String Outspread
- ZOJ 2571 Big String Outspread
- Big String
- zoj 1526 Big Number
- zoj 1526 Big Number
- zoj 1526 Big Number 数学
- String的Big-Three
- B - Big String
- poj 2887 Big String
- POJ 2887 Big String
- poj 2887 Big String
- poj 2887 Big String
- zoj1633 Big String dfs
- Android UI 设计(13):AutoCompleteTextView
- java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/LoopTag 解决方法
- centos6.5安装php5.6版本
- 九度考研真题 浙大 2008-2浙大 题目1029:魔咒词典 字符串比较
- (从头做DP)HDU 1025 Constructing Roads In JGShining's Kingdom
- ZOJ - 1633 Big String
- scala+java+eclipse+maven开发环境构建
- oracle11g ocm考试总结
- DBCP连接池配置参数
- NavMeshAgent
- 20151024_001_C#基础知识(静态与非静态的区别,值类型和引用类型,堆和栈的区别,字符串的不可变性,命名空间)
- jxl,poi导出Excel时单元格格式问题
- 不跑boot的修改
- Vijos1347 乘积最大