问题 F: Folding a Ribbon

时间限制: 1 Sec  内存限制: 128 MB
提交: 11  解决: 9
[提交] [状态] [讨论版] [命题人:admin]

题目描述

Think of repetitively folding a very long and thin ribbon. First, the ribbon is spread out from left to right, then it is creased at its center, and one half of the ribbon is laid over the other. You can either fold it from the left to the right, picking up the left end of the ribbon and laying it over the right end, or from the right to the left, doing the same in the reverse direction. To fold the already folded ribbon, the whole layers of the ribbon are treated as one thicker ribbon, again from the left to the right or the reverse. 
After folding the ribbon a number of times, one of the layers of the ribbon is marked, and then the ribbon is completely unfolded restoring the original state. Many creases remain on the unfolded ribbon, and one certain part of the ribbon between two creases or a ribbon end should be found marked. Knowing which layer is marked and the position of the marked part when the ribbon is spread out, can you tell all the directions of the repeated folding, from the left or from the right? 
The figure below depicts the case of the first dataset of the sample input.

输入

The input consists of at most 100 datasets, each being a line containing three integers. 
n i j
The three integers mean the following: The ribbon is folded n times in a certain order; then, the i-th layer of the folded ribbon, counted from the top, is marked; when the ribbon is unfolded completely restoring the original state, the marked part is the j-th part of the ribbon separated by creases, counted from the left. Both i and j are one-based, that is, the topmost layer is the layer 1 and the leftmost part is numbered 1. These integers satisfy 1 ≤ n ≤ 60, 1 ≤ i ≤ 2n, and 1 ≤ j ≤ 2n. 
The end of the input is indicated by a line with three zeros.

输出

For each dataset, output one of the possible folding sequences that bring about the result specified in the dataset. 
The folding sequence should be given in one line consisting of n characters, each being either L or R. L means a folding from the left to the right, and R means from the right to the left. The folding operations are to be carried out in the order specified in the sequence.

样例输入

3 3 2
12 578 2214
59 471605241352156968 431565444592236940
0 0 0

样例输出

LRR
RLLLRRRLRRLL
LRRRLRRLLRRRRLLLLRLLRRRLRRLLRLLLLLLRLRLLRLRLLLRLRLLRLLRRRLL

题目大意是说给你一张纸,每次向左或者向右折,告诉你折了N次以后从上向下数第i个在折叠前是第j部分,求从第一次到第N次是分别是向左折还是向右折。

我的解法是先从后往前求每次折叠以后第j个在从下向上数第cnt[i]个位置(如果cnt[i] < 厚度的一半,则cnt[i-1]=cnt[i];否则cnt[i-1]  = 厚度-cnt[i]+1,即是从下半部分折叠上来的),求出所有的cnt[i]之后,再从前往后遍历。因为如果是把改点折叠到另一半上面,则它的位置会上浮,否则保持不变,与此同时,我们更新这个点是当前从左往右数第几个,即可知道当前点是在左半边还是右半边,再根据cnt[i]的变化即可得到折叠方向。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100005;
ll poww[64];
ll cntt[100];
int cnt = 0;
int main()
{
//    freopen("in.txt", "r", stdin);ll n,m,k;poww[0] = 1;for (int i = 1; i <= 62; i++)poww[i] = poww[i - 1] << 1;while (~scanf("%lld%lld%lld",&n,&m,&k)){if (!n && !m && !k)break;m = cntt[n] = poww[n] - m + 1;for (cnt = n; cnt > 1; cnt--){if (m > poww[cnt - 1])m = poww[cnt] - m + 1;cntt[cnt - 1] = m;}for (int i = 1; i <= n; i++){if (k <= poww[n - i]){if (cntt[i] <= poww[i - 1])printf("R");else{printf("L");k = poww[n - i] - k + 1;}}else{if (cntt[i] > poww[i - 1]){printf("R");k = poww[n - i + 1] - k + 1;}else{printf("L");k -= poww[n - i];}}}puts("");}return 0;
}

Folding a Ribbon(思维)相关推荐

  1. [思维]Folding a Ribbon

    题目描述 Think of repetitively folding a very long and thin ribbon. First, the ribbon is spread out from ...

  2. 《算法竞赛入门经典(第2版)》——学习记录

    前言:   这里主要记录本人在学习紫书过程中充分理解过的题目的AC代码,便于以后回顾时查找代码和思路,毕竟看别人的真的有点难懂.此外,本书甚至是本书之外的相关知识学习也可能在此留下记录.   作为一只 ...

  3. 查漏补缺:2020年搞定SpringCloud面试(含答案和思维导图)

    前言 Spring Cloud是一系列框架的有序集合.它利用Spring Boot的开发便利性巧妙地简化了分布式系统基础设施的开发,如服务发现注册.配置中心.消息总线.负载均衡.断路器.数据监控等,都 ...

  4. 思维导图分享以及MindManager使用说明

    来源于: http://www.cnblogs.com/muhongxing/archive/2009/12/22/1628782.html http://www.cnblogs.com/muhong ...

  5. springCloud五大神兽(思维导图)

    SpringCloud的五大件 思维导图 服务发现--Netflix Eureka 客服端负载均衡--Netflix Ribbon 断路器--Netflix Hystrix 服务网关--Netflix ...

  6. 支持幻灯片演示的思维导图软件NovaMind

    NovaMind 是一款带有演示功能的思维导图绘制软件,据说苹果版 NovaMind 在业内名声很好,其实 Windows 版也同样优秀,woodheadz 在布局.图形.连接线等方面对比 NovaM ...

  7. 支持幻灯片演示的思维导图软件NovaMind_我是亲民_新浪博客

    NovaMind 是一款带有演示功能的思维导图绘制软件,据说苹果版 NovaMind 在业内名声很好,其实 Windows 版也同样优秀,woodheadz 在布局.图形.连接线等方面对比 NovaM ...

  8. SpringCloud组件:Ribbon负载均衡策略及执行原理!

    大家好,我是磊哥. 今天我们来看下微服务中非常重要的一个组件:Ribbon.它作为负载均衡器在分布式网络中扮演着非常重要的角色. 本篇主要内容如下: 在介绍 Ribbon 之前,不得不说下负载均衡这个 ...

  9. 敖丙思维导图-Spring

    敖丙思维导图系列目录 这些知识整理都是自己查阅帅丙资料(当然还有其他渠道)加以总结滴~ 每周都会更新知识进去. 如有不全或错误还请大家在评论中指出~ 敖丙思维导图-集合 敖丙思维导图-多线程之sync ...

最新文章

  1. 权威解答495个最常遇到的C语言问题
  2. 对复杂业务组件在实际开发过程中被调用的反思
  3. Google Hack 搜索使用
  4. laravel controller
  5. Eclipse卸载Groovy Development tool时,为什么要去查询hana.ondemand.com的资源?
  6. INF DestinationDirs Section
  7. 组件化开发-002-Cocoapods远程私有库使用(Private Repo)
  8. WinHTTP Web Proxy Auto-Discovery Service
  9. python整个小服务器
  10. java编译程序文件为_编译Java源程序文件后将产生相应的可执行字节码文件,这些文件的扩展名为( )。...
  11. 面试总结——Java篇
  12. 中国省份城市数据库表
  13. 编译QT项目出现错误:error C2144: syntax error : 'void' should be preceded by ';'
  14. 51单片机教程 :(一) 开发环境的搭建
  15. python可以做数据库功能吗_python可以用哪些数据库
  16. echart vue
  17. 无问东西:你曾是少年
  18. play框架在idea开发工具上的简单配置
  19. 学习 FPGA 经验与书籍分享。
  20. Integral Object Mining via Online Attention Accumulation

热门文章

  1. 闰年与非闰年的判定算法
  2. ASP网站如何防止注入漏洞攻击
  3. 跨域问题的产生原因和相应的解决方式
  4. 如何用手机拍出精彩的 Vlog?
  5. App 推广有哪些小技巧?
  6. 软件测试入门之测试模型
  7. QCSPCChart SPC for Java
  8. 分享一个seo超级外链发布网站
  9. [No0000139]轻量级文本编辑器,Notepad最佳替代品:Notepad++
  10. WebView交互架构项目实战(三):多进程WebView使用实践