zoukankan      html  css  js  c++  java
  • 想不下去的题目放这有机会用手机看。。。

    293. Game with Q an C

    time limit per test: 0.5 sec.
    memory limit per test: 65536 KB
    input: standard
    output: standard



    Qc and He play the following game. 
    Each turn He writes one of the two letters "Q" or "C" on the fence. The new letter is added to the end of the string formed by the previous letters. Players move alternately and on his turn Qc can either swap two already written letters, or do nothing (pass). On his first turn Qc obviously passes. 
    Qc's goal is to play in such way that in each his odd turn (1,3,5,7,...) letters on the fence form a palindrome (word that is reading the same in either direction). Occasionally Qc knows the sequence of letters that He is going to say and now Qc wants to know whether his goal is achievable. 
    Help Qc to find an appropriate sequence of turns or say that such sequence does not exist.

    Input
    The first line of the input file contains n (1 <= n <= 2005), n means that He will write 2n-1 letters on the fence. The second line contains the sequence of 2n - 1 letters that He is going to say. Each letter is only "Q" or "C".

    Output
    On the first line of the output print word "Qc" if the Qc's goal is achievable, otherwise print "He". If the first line is "Qc" then the following lines of the output should each contain two numbers separated by one space. Here "0 0" indicates the doing nothing and "q c" indicates the swapping of letters at positions q and c. 
    If there are more than one solutions print any one. 


    Sample test(s)

    Input

    
    
    Test #1
    4
    QCCQCQQ
    Test #2
    1
    Output
    
    
    Test #1 
    Qc 
    0 0 
    0 0 
    1 2 
    3 4 
    3 4 
    0 0 
    1 4 

    Test #2 
    Qc 
    0 0 

  • 相关阅读:
    20145129 《Java程序设计》第1周学习总结
    问卷调查
    第十二周学习笔记
    第十一周学习总结
    信息安全系统设计基础实验二—20135214万子惠20135227黄晓妍
    信息安全系统设计基础实验一—20135227黄晓妍 20135214万子惠
    第九周学习报告
    家庭作业
    期中总结
    第七周学习报告:)
  • 原文地址:https://www.cnblogs.com/java20130723/p/3212199.html
Copyright © 2011-2022 走看看