horiuchi #5549(2008/01/29 07:01 GMT) [ Java ] Rating0/0=0.00
富豪的にシャッフル毎に配列を生成。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Sample140 { public final int n; private int[] cards; public Sample140(int n) { this.n = n; cards = new int[2 * n]; for (int index = 0; index < cards.length; index++) { cards[index] = index + 1; } } public void shuffle(int k) { int[] after = new int[2 * n]; if (k == 0) { for (int index = 0; index < after.length; index++) { int r = index % 2; after[index] = cards[index / 2 + r * n]; } } else { for (int index = 0; index < after.length; index++) { int i = index + k - 2 * n; if (i < 0) i += 2 * n; after[index] = cards[i]; } } cards = after; } public int[] calc() { return cards; } public static void main(String[] args) { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); try { int n = Integer.parseInt(reader.readLine()); Sample140 sample = new Sample140(n); int m = Integer.parseInt(reader.readLine()); for (int index = 0; index < m; index++) { int k = Integer.parseInt(reader.readLine()); sample.shuffle(k); } int[] result = sample.calc(); for (int i: result) { System.out.println(i); } } catch (IOException ex) { ex.printStackTrace(); } } }
Rating0/0=0.00-0+
[ reply ]
horiuchi
#5549()
[
Java
]
Rating0/0=0.00
富豪的にシャッフル毎に配列を生成。
Rating0/0=0.00-0+
[ reply ]