Some time ago, the company colleagues asked a killing games feeling or very interesting, for our program ape, as long as there are rules, everything can be expressed in code (the idea of the Cock Silk program ape).
The title is this: there are 1000 criminals, who are numbered sequentially (starting from 1). First, the judge asked an even number of people to stand up and kill. They are then numbered sequentially without disrupting the original order. Then the judge Jenchie the number of people to stand up and kill. One analogy. Q: What was the last person in the 1000? (Don't ask me why the judge wanted to kill someone like that) the following is a personal code, please enlighten me.
int tag = 1;//number of killings int num = 1000;//criminals in the first few arraylist<string> list = new ArrayList<String> ();//list collection of criminals arraylist<string> list0 = new Arraylist<string> ();//To kill the Criminal Code, to remove List0.add ("0") from the list;for (int i = 1; i <= num; i++) {//the offender list.add (i + "");} while (True) {//set the person to be killed as 0 if (tag % 2 == 1) {// for (int i = 1; i <= List.size (); i++) { if ( i % 2 == 0) { list.set (i - 1, 0 + ""); &nBSP;} } } else { for (Int i = 1; i <= list.size (); i++ ) { if (i % 2 ==&NBSP;1) { list.set (i - 1, 0 + ""); } } } list.removeall (LIST0);//Kill the criminals, re-number tag ++;//kill Count plus 1 if (List.size () == 1) {//when there's only one left, output this number system.out.print ( List.get (0). toString ()); return; }}
Killing games implementation of Java code