有30个人 围成一个圆圈 
1    2      3        4    5     6     7         8     9    10 。30
红   蓝     黄     以此类推蓝球传递方式 3 5 10 15 25 30 3
红球传递方式 2 4 6 8 10 。。
黄球传递方式 1 2 3 4 5。。
一开始 红色1号人物持黄球 蓝色2号人物持红球 黄色三号人物持蓝球
 求 第一次出现红色人物拿红球 蓝色人物拿蓝球 黄色人物拿黄球 的时候
红蓝黄人物各是几号

解决方案 »

  1.   

    给过你了
    public class TestStatic {
    public String[] s = { "1", "2", "3", "4", "5", "6" }; public void run() {
    int j2;
    int sLength = s.length;
    for (int i = 0; i < getP(s.length); i++) {
    String[] tempString = s.clone();
    for (int j = 0; j < i; j++) {
    j2 = j % (sLength - 1);
    change(j2, tempString);
    }
    if (isR(tempString)) {
    print(tempString);
    }
    }
    } public int getP(int i) {
    int all = 1;
    for (int j = i; j > 0; j--) {
    all = all * j;
    }
    return all;
    } public void change(int i, String[] tempString) {//
    String t = "";
    t = tempString[i];
    tempString[i] = tempString[i + 1];
    tempString[i + 1] = t;
    } public boolean isR(String b[]) {
    if (b[0] != "4") {
    return false;
    }
    int index_2 = 0;
    int index_3 = 0;
    for (int i = 0; i < b.length; i++) {
    if (b[i] == "2") {
    index_2 = i;
    } else if (b[i] == "3") {
    index_3 = i;
    }
    }
    if (Math.abs(index_2 - index_3) == 1) {
    return false;
    }
    return true;
    } public void print(String b[]) {
    for (int i = 0; i < b.length; i++) {
    System.out.print(b[i]);
    }
    System.out.println();
    } public static void main(String[] args) {
    TestStatic fa = new TestStatic();
    fa.run();
    }
    }
    结果
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
    435612
    453612
    456312
      

  2.   


    public class Test {    public static void main(String[] args) {        Color[] members = new Color[30];
            for (int i = 0; i < 10; i++) {
                members[i * 3] = Color.Red;
                members[i * 3 + 1] = Color.Blue;
                members[i * 3 + 2] = Color.Yellow;
            }        int[] ruleBlue = new int[30];
            ruleBlue[3 - 1] = 5 - 1;
            ruleBlue[5 - 1] = 10 - 1;
            ruleBlue[10 - 1] = 15 - 1;
            ruleBlue[15 - 1] = 25 - 1;
            ruleBlue[25 - 1] = 30 - 1;
            ruleBlue[30 - 1] = 3 - 1;        int[] ruleRed = new int[30];
            for (int i = 0; i < 14; i++) {
                ruleRed[i * 2 + 1] = i * 2 + 3;
            }
            ruleRed[29] = 1;        int[] ruleYellow = new int[30];
            for (int i = 0; i < ruleYellow.length - 1; i++) {
                ruleYellow[i] = i + 1;
            }
            ruleYellow[ruleYellow.length - 1] = 0;        int yellowStart = 1 - 1;
            int redStart = 2 - 1;
            int blueStart = 3 - 1;        int yellow = yellowStart;
            for (; members[yellow] != Color.Yellow; yellow = ruleYellow[yellow])
                ;
            System.out.println("yellow :" + (yellow + 1));        int red = redStart;
            for (; members[red] != Color.Red; red = ruleRed[red])
                ;
            System.out.println("red :" + (red + 1));        int blue = blueStart;
            for (; members[blue] != Color.Blue; blue = ruleBlue[blue])
                ;
            System.out.println("blue :" + (blue + 1));    }    enum Color {
            Red, Blue, Yellow;
        }
    }输出:
    3
    4
    5