結果
問題 | No.133 カードゲーム |
ユーザー |
![]() |
提出日時 | 2015-01-28 01:37:32 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 34 ms / 5,000 ms |
コード長 | 2,227 bytes |
コンパイル時間 | 858 ms |
コンパイル使用メモリ | 113,884 KB |
実行使用メモリ | 20,224 KB |
最終ジャッジ日時 | 2024-06-25 03:28:51 |
合計ジャッジ時間 | 2,378 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace YukiCoder2{class Program{public static bool NextPermutation<T>(T[] array, int start, int length)where T : IComparable{int end = start + length - 1;if (end <= start) return false;int last = end;while (true){int pos = last--;if (array[last].CompareTo(array[pos]) < 0){int i;for (i = end + 1; array[last].CompareTo(array[--i]) >= 0; ) { }T tmp = array[last]; array[last] = array[i]; array[i] = tmp;Array.Reverse(array, pos, end - pos + 1);return true;}if (last == start){Array.Reverse(array, start, end - start);return false;}}throw new Exception("NextPermutation: Fatal error");}static void Main(string[] args){var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();var n = line[0];var aCards = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();Array.Sort(aCards);var bCards = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();Array.Sort(bCards);int sum = 0;int total = 0;do{var bCopy = bCards.ToArray();do{int win = 0;for (int i = 0; i < n; i++){if (aCards[i] > bCopy[i]){win++;}}if (win > n/2){sum++;}total++;} while (NextPermutation(bCopy, 0, n));} while (NextPermutation(aCards, 0, n));Console.WriteLine(sum / (double)total);}}}