Add tags

Add tags to the following comment

Javaで素朴な実装をしてみました。100000 で約6秒でした。 最初は、LinkedListで実装したのですが計測したところArrayListの方が早かったです。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import java.util.ArrayList;
import java.util.List;

public class Answer79 {
    public static int choice(int count, int start, int move) {
        List<Integer> list = new ArrayList<Integer>();
        for (int index = 0; index < count; index++) list.add(index);

        for (int index = (start - 1) % count; list.size() > 1; index = (index - 1 + move) % list.size()) {
            list.remove(index);
        }
        return list.get(0) + 1;
    }

    public static void main(String[] args) {
        System.out.println(choice(8, 5, 3));
        System.out.println(choice(10000, 10000, 10000));
        System.out.println(choice(100000, 100000, 100000));
    }
}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...