ZOJ 1633 Big String(模拟构造)
来源:互联网 发布:杭州淘宝运营助理招聘 编辑:程序博客网 时间:2024/06/05 11:53
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
题意:开始时有两个字符串,A = "^__^" (four characters), B = "T.T" (three characters),然后重复执行C=BA,A=B,B = C,问第n个字符是什么。
分析:因为最终的字符串是从前往后递推出来的,所以再求解时,我们可以把这个过程逆过去,直到字符串的长度不超过7,输出即可。
#include<iostream>#include<string>using namespace std;typedef long long LL;LL a[95]; //保存字符串的长度int main(){ string C = "T.T^__^"; a[0] = 4; a[1] = 3; int i; for(i = 2; i < 90; i++) a[i] = a[i-1] + a[i-2]; LL n; while(cin >> n) { while(n > 7) { int pos = lower_bound(a, a+89, n) - a; n -= a[pos-1]; } cout << C[n-1] << endl; } return 0;}
0 0
- ZOJ 1633 Big String(模拟构造)
- ZOJ1633-构造模拟-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
- string 模拟之-big three
- ZOJ 3490 String Successor(模拟啊 )
- ZOJ 3490 String Successor(模拟)
- hdu5414 CRB and String(构造,模拟)
- ZOJ 3952 Fibonacci Sequence Chicken Edition(构造/模拟)
- ZOJ 3490String Successor(模拟)
- zoj 3490 String Successor 模拟
- ZOJ- 3490 String Successor 模拟
- ZOJ Problem Set - 3490 String Successor(字符串模拟)
- codeforces 709D Recover the String (构造+模拟)
- mongodb 连接池
- 无法应用变更! 请先修复损毁的软件包
- 【初学python】错误SSLError: [Errno 1] _ssl.c:504:的解决记录
- Java之泛型
- MSRA实习结束
- ZOJ 1633 Big String(模拟构造)
- 关于从字符串中提取一串数字的代码
- java awt 页面布局
- hdu 2188
- hdu 2516
- Jetty学习(一)嵌入应用之Helloworld
- 修改vs2010编译器不支持inttypes.h的问题
- thinkphp的各种内部函数 D()、F()、S()、C()、L()、A()、I()详解
- 多种博弈