LintCode 842: Origami
题目:
842. Origami
Origami, each time the paper is folded from right to left, the dent is 0, the bump is 1. After the n number of folds, find the 01 sequence of the creases formed with the paper unrolling.
Example
Given n = 1, return “0”.
Explanation:
the 01 sequence of the creases is “0”.
Given n = 2, return “001”.
Explanation:
the 01 sequence of the creases is “001”.
Notice
1 <= n <= 20
我们可看出一些规律:
#1: 0
#2: 001
#3: 0010011
#4: 001001100011011
设第i次结果为s, 那么第i+1次结果为s + ‘0’ + s.reverse().flip()。
例如: 001001100011011 = 0010011 + ‘0’ + 0011011
其中0011011即0010011的0/1互换 并倒转。
class Solution {
public:/*** @param n: The folding times* @return: the 01 string*/string getString(int n) {string s = "0";for (int i = 2; i <= n; ++i) {string reverseS;int len = s.size();s.push_back('0');for (int j = 0; j < len; ++j) {s.push_back(1 ^ (s[len - 1 - j] - '0') + '0');}}return s;}
};
LintCode 842: Origami相关推荐
- LintCode 249. 统计前面比自己小的数的个数
给定一个整数数组(下标由 0 到 n-1, n 表示数组的规模,取值范围由 0 到10000).对于数组中的每个 ai 元素,请计算 ai 前的数中比它小的元素的数量. 注意事项 We suggest ...
- LintCode: Max Tree
题目 Given an integer array with no duplicates. A max tree building on this array is defined as follow ...
- 【LintCode: 3. 统计数字】算法题解析
这是一道来自LintCode的算法题目,本文用C++来解答这道题,链接为: https://www.lintcode.com/problem/digit-counts/description 题目描述 ...
- LintCode 1.A+B的问题
LintCode 1.A+B的问题 描述 给出两个整数 a 和 b , 求他们的和. 答案 public class Solution {/*** @param a: An integer* @par ...
- 关于爬楼梯的lintcode代码
讲真的,这个我只会用递归去做,但是lintcode上面超时,所以只有在网上找了个动态规划的,虽然这个程序懂了,但是我觉得还是挺不容易的真正弄懂的话-- class Solution { public: ...
- lintcode: k Sum 解题报告
K SUM My Submissions http://www.lintcode.com/en/problem/k-sum/ 题目来自九章算法 13% Accepted Given n distinc ...
- LintCode Longest Increasing Continuous Subsequence
原题链接在这里:http://www.lintcode.com/en/problem/longest-increasing-continuous-subsequence/ 题目: Give an in ...
- lintcode 滑动窗口的最大值(双端队列)
题目链接:http://www.lintcode.com/zh-cn/problem/sliding-window-maximum/# 滑动窗口的最大值 给出一个可能包含重复的整数数组,和一个大小为 ...
- leetcode 293.Flip Game(lintcode 914) 、294.Flip Game II(lintcode 913)
914. Flip Game https://www.cnblogs.com/grandyang/p/5224896.html 从前到后遍历,遇到连续两个'+',就将两个加号变成'-'组成新的字符串加 ...
- Origami – 用于 Quartz 的免费的交互设计框架
Origami 是一个为 Quartz Composer 开发的免费的工具包--由Facebook设计团队创建,让交互设计原型更加简单,不需要编程. 如今,大多数设计师通过创建静态原型来表达要实现的应 ...
最新文章
- 一口气说出 5 种 IO 模型,蒙圈了!
- C# 正则表达式过滤危险HTML
- 学生用计算机说明方法,15.文中多处运用了作比较的说明方法.请任选一例.说说运用这种方法的作用. 例子: 作用:...
- 条件概率分布_条件概率
- oracle values函数,Oracle文本函数简介
- flutter 轮播图动态加载网络图片
- Google Maps JavaScript API V3 官方网站
- 老式Windows桌面的终结:Windows 11来了,DaaS还会远吗?
- ios程序中调用腾讯OpenAPI时遇到的问题
- 十六进制高低位转换,返回十进制数
- python点云可视化
- 寻路算法 --- A星寻路算法
- 关于用c语言演奏《天空之城》那些事
- html5 梵高 星,上海梵高星空艺术馆门票
- 蓝牙耳机品牌排行榜,连接稳定的四款蓝牙耳机分享
- 08_基于IP的伪装
- 易语言-王者天下页游自动回收辅助
- torch对于tensor的常规操作
- python 一些模块的应用
- SDSoC软硬件协同设计流程系列——1.基于SDSoC的软硬件协同设计流程简介