Swordsmanship-question solution and question Solution

Source: Internet
Author: User

Swordsmanship-question solution and question Solution
Title: swordsmanship


During the Ancient Funeral Activities, you are often asked to do things. After the ceremony, there are sometimes interesting programs of "Swordsmanship" to ease the depressing atmosphere.


The program's major steps are: First Use grain (usually rice) to "Draw" several steps on the ground (indicating N-level float ). Several other monks randomly "stood" on a certain level. The highest level must be set to others. (1)


The two masters of the game respectively directed a monk up to any level, but they were blocked by the monk standing on the level. The two monks cannot stand on the same level or move to the lower level.


The two masters send commands in turn. In the end, all the monks are bound to be in the upper steps and cannot move up any more. If it is the turn of the mage to continue to move, the game is over and the mage admits defeat.


For the known number of steps and the distribution location of the monk, Please calculate how the mage with the first command can make a decision to ensure the winner.


The input data is a row of N integers separated by spaces, indicating the location of the monk. The step number starts from 1, so the last monk's position is the total number of steps. (N <100, total number of steps <1000)

The output is two integers separated by spaces: a B, indicating that the monk at the position A is moved to the position B. If there are multiple solutions, the solution with A smaller value is output. If there is no solution,-1 is output.




For example:
User input:
1 5 9
Program output:
1 4


Another example is:
User input:
1 5 8 10
Program output:
1 3


Resource conventions:
Peak memory consumption <64 M
CPU consumption <1000 ms

Please output strictly as required. Do not print anything that is similar to "Please input.


All codes are stored in the same source file. After debugging is successful, copy and submit the source code.


Note: The main function must return 0.
Note: Only ansi c/ansi c ++ standards are used. Do not call special functions that depend on the compiling environment or operating system.
Note: All dependent functions must be explicitly included in the source file # include <xxx>. Common header files cannot be omitted through engineering settings.

When submitting a file, select the expected compiler type (do not confuse c and cpp ).




Import java. util. Tips;/***** swordsmanship ** solution: a method that can be converted into a Nim game. * ** Test data: * 1 5 8 19 22 34 56 78 100*34 51*56 75 *** 1 2 0 4 0*1 3 6 7 12 13*0 1 2 3 **/public class Asist {public static void main (String [] args) {pipeline SC = new pipeline (System. in); String [] ss = SC. nextLine (). split (""); int a [] = new int [ss. length]; for (int I = 0; I <. length; I ++) a [I] = Integer. parseInt (ss [I]); // temporary array -- number of cells between monk int B [] = new int [. length]; int b1 = 0; for (int I = 1; I <. length; I ++) {B [b1 ++] = a [I]-a [I-1]-1;} // converts it to Nim for int sum = 0; for (int I = 0; I <= b1; I + = 2) {sum ^ = B [I];} if (sum = 0) System. out. println ("-1"); else {// mobile of all monks, brute force CRACKING for (int I = 0; I <. length; I ++) {for (int j = 1; j <= B [I]; j ++) {B [I]-= j; if (I! = 0) B [I-1] + = j; sum = B [0]; for (int k = 2; k <= b1; k + = 2) {sum ^ = B [k];} if (sum = 0) {System. out. println (a [I] + "" + (a [I] + j); break;} // trace back B [I] + = j; if (I! = 0) B [I-1]-= j ;}}}}}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.