zoukankan      html  css  js  c++  java
  • Play with Chain

    题目描述

    YaoYao is fond of playing his chains. He has a chain containing n diamonds on it. Diamonds are numbered from 1 to n. 
    At first, the diamonds on the chain is a sequence: 1, 2, 3, …, n. 
    He will perform two types of operations: 
    CUT a b c: He will first cut down the chain from the ath diamond to the bth diamond. And then insert it after the cth diamond on the remaining chain. 
    For example, if n=8, the chain is: 1 2 3 4 5 6 7 8; We perform “CUT 3 5 4”, Then we first cut down 3 4 5, and the remaining chain would be: 1 2 6 7 8. Then we insert “3 4 5” into the chain before 5th diamond, the chain turns out to be: 1 2 6 7 3 4 5 8. 

    FLIP a b: We first cut down the chain from the ath diamond to the bth diamond. Then reverse the chain and put them back to the original position. 
    For example, if we perform “FLIP 2 6” on the chain: 1 2 6 7 3 4 5 8. The chain will turn out to be: 1 4 3 7 6 2 5 8 

    He wants to know what the chain looks like after perform m operations. Could you help him? 

    给一个数列,初始时为 1, 2, 3, ..., n,现在有两种共 m 个操作
      操作1. CUT a b c 表示把数列中第 a 个到第 b 个从原数列中删除得到一个新数列,并将它添加到新数列中第 c 个数的后面
      操作2. FLIP a b 表示把数列中第 a 个数到第 b 个数翻转
    经过 m 个操作之后,输出这个数列

    输入

    There will be multiple test cases in a test data. 
    For each test case, the first line contains two numbers: n and m (1≤n, m≤3*100000), indicating the total number of diamonds on the chain and the number of operations respectively. 
    Then m lines follow, each line contains one operation. The command is like this: 
    CUT a b c // Means a CUT operation, 1 ≤ a ≤ b ≤ n, 0≤ c ≤ n-(b-a+1). 
    FLIP a b    // Means a FLIP operation, 1 ≤ a < b ≤ n. 
    The input ends up with two negative numbers, which should not be processed as a case. 

    输出

    For each test case, you should print a line with n numbers. The ith number is the number of the ith diamond on the chain.

    样例输入

    8 2 CUT 3 5 4 FLIP 2 6 -1 -1

    样例输出

    1 4 3 7 6 2 5 8

    提示

    PEACE
  • 相关阅读:
    mysql开启skip-name-resolve 导致root@127.0.0.1(localhost)访问引发的ERROR 1045 (28000)错误解决方案
    php的类型运算符instanceof(用于确定一个 PHP 变量是否属于某一类 class 的实例)
    PHP通过__call实现简单的AOP(主事务后的其他操作)比如前置通知,后置通知
    页面返回刷新或H5监听(手机的)返回键
    微信公众号分享的引导页(附素材)
    mysql服务器无法连接10055错误解决示例
    Eclipse安装svn插件的几种方式
    mysql导入和导出数据
    eclipse的常用快捷键
    springmvc乱码配置
  • 原文地址:https://www.cnblogs.com/gshdyjz/p/7263544.html
Copyright © 2011-2022 走看看