According to matrix67's article "prisoner and Lightbulb:
Public class wakeup {static class people {// records the position 0 determined when the first entry is made.-1 left and 1 right. public int position; // the ball on the hand public int ballnum; // identifies the public int ID; // whether the ball is still in the seesaw game public Boolean online; Public people (int id) {This. id = ID; position = 0; ballnum = 2; online = true ;}} Private Static int lelecount = 100; // Number of participants Private Static Boolean boxisempty = true; // whether the box is empty Private Static Boolean leftisweight = false; // The lower public s on the left of the seesaw Tatic void main (string [] ARGs) {People [] thepeoples = new people [100]; for (INT I = 0; I <peoplecount; I ++) {thepeoples [I] = new people (I);} Boolean finished = false; int K = 0; int I = 0; int outnum = 0; while (! Finished) {k ++; I = (new random (). nextint (peoplecount) % peoplecount; people Thep = thepeoples [I]; If (Thep. online) {If (Thep. position = 0) {Thep. position = leftisweight? -1: 1; leftisweight =! Leftisweight;} else {If (Thep. Position =-1) {If (leftisweight) {// The left-side low. If there is a ball, take if (! Boxisempty) {boxisempty = true; Thep. ballnum ++ ;}} else {// height of the current side. If it is null, place the ball if (boxisempty) {If (Thep. ballnum> 0) {Thep. ballnum --; boxisempty = false ;}}} else {If (leftisweight) {// The height of the current side. If it is empty, put the ball if (boxisempty) {If (Thep. ballnum> 0) {Thep. ballnum --; boxisempty = false ;}} else {// The current side is low. If (! Boxisempty) {boxisempty = true; Thep. ballnum ++ ;}}}// exit if no ball exists and if (Thep) is not used. ballnum <= 0) {leftisweight =! Leftisweight; Thep. online = false; outnum ++; system. out. println ("out:" + Thep. ID);} // If 200 or 199 balls are collected and the other ball is in the box, it indicates victory. if (Thep. ballnum + (boxisempty? 0: 1)> = peoplecount * 2) {system. out. println ("Winner:" + Thep. ID + ", executed in total:" + k); finished = true ;}}}}}
PS: This algorithm provides a good idea, but it is generally not used in actual election policies, because the conditions are not as harsh as the scenario assumes in the article.