horiuchi #5516(2008/01/28 09:40 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 56 57 58 59 60 61 62 63 64 65 66 67
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; public class Sample133 { private final int count; private final SortedSet<Integer> tarouCardList_ = new TreeSet<Integer>(); public Sample133(int n) { this.count = n; } public void add(int card) { tarouCardList_.add(card); } public int[] calc() { SortedSet<Integer> hanakoCardList = createOtherCardList(count * 2, tarouCardList_); int board = 0; for (int turn = 0; true; turn++) { SortedSet<Integer> cardList = (turn % 2 == 0)? tarouCardList_: hanakoCardList; SortedSet<Integer> tailSet = cardList.tailSet(board); if (tailSet.isEmpty()) { board = 0; continue; } int card = tailSet.first(); cardList.remove(card); board = card; if (cardList.isEmpty()) break; } return new int[] {hanakoCardList.size(), tarouCardList_.size()}; } private SortedSet<Integer> createOtherCardList(int max, Set<Integer> list) { SortedSet<Integer> result = new TreeSet<Integer>(); for (int card = 1; card <= max; card++) { if (!list.contains(card)) { result.add(card); } } return result; } public static void main(String[] args) { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); try { final int n = Integer.parseInt(reader.readLine()); Sample133 sample = new Sample133(n); for (int index = 0; index < n; index++) { sample.add(Integer.parseInt(reader.readLine())); } int[] result = sample.calc(); for (int i: result) { System.out.println(i); } } catch (IOException ex) { ex.printStackTrace(); } } }
Rating0/0=0.00-0+
[ reply ]
horiuchi
#5516()
[
Java
]
Rating0/0=0.00
今回はちゃんと、標準入力から受け取り標準出力へ解答を表示するようにしました。
Rating0/0=0.00-0+
[ reply ]