Big String 二分法的问题
来源:互联网 发布:贵阳房价上涨知乎 编辑:程序博客网 时间:2024/05/23 01:12
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^__^".
Your task is to find out the n-th character of this infinite string.
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
题意:很简单就是找给定位置的字符
思路:二分
AC代码:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
long long n;
char c[] = "T.T^__^";
long long a[92];
long long erfen(){
long long left = 0,mid;
long long right = 89;
while(left < right){
mid = left + (right - left)/2;
if(a[mid] >= n){
right = mid;
}
else{
left = mid + 1;
}
}
return right;//然会大于等于n的数组的下标
}
int main()
{
a[0] = 4;
a[1] = 3;//两个顺序不能变啊,wa了n次
long long i;
for(i = 2 ; i < 90 ; i++){
a[i] = a[i-1] + a[i-2];
}
while(cin >> n){
while(n > 7){
long long mid = erfen();
n -= a[mid-1];
}
cout << c[n-1] << endl;
}
return 0;
}
简直就是渣渣,这道题想太长时间,花了太多精力,懂了很多。。。
- Big String 二分法的问题
- String的Big-Three
- Big String
- 二分法小程序的问题
- 二分法的向上向下取整问题
- zoj 1633 Big String
- B - Big String
- poj 2887 Big String
- POJ 2887 Big String
- poj 2887 Big String
- ZOJ - 1633 Big String
- poj 2887 Big String
- zoj1633 Big String dfs
- jBPM的type问题,big bug!
- leetcode 87. Scramble String 二分法
- 二分法专题-lintcode二分法问题解惑
- 从函数的零点问题到二分法的应用
- Collections 二分法查找问题
- 单链表排序
- 趣谈直方图均衡化和规定化
- Java发送邮件javax.mail
- 《数据结构(严蔚敏版)》学习笔记(三)——栈实现数制转换
- Memcache基础教程 && Ubuntu 安装Memcache服务
- Big String 二分法的问题
- 网页中多个table嵌套的一些小技巧
- A-B Game
- Tomcat 8熵池阻塞变慢详解
- Activity的Launch mode详解 singleTask正解
- 利用mysql的amoeba实现主从和读写分离
- iOS SDK开发时,有关OC和C++混编造成其它类错误的问题(Compile Sources As Objective-C++)
- 欢迎使用CSDN-markdown编辑器
- App启动页加载图片