結果
問題 | No.133 カードゲーム |
ユーザー |
![]() |
提出日時 | 2017-01-12 17:20:24 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 28 ms / 5,000 ms |
コード長 | 3,508 bytes |
コンパイル時間 | 960 ms |
コンパイル使用メモリ | 106,880 KB |
実行使用メモリ | 18,816 KB |
最終ジャッジ日時 | 2024-06-25 03:45:12 |
合計ジャッジ時間 | 2,431 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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;using System.Collections.Generic;using System.Collections.Specialized;using System.Text;using System.Text.RegularExpressions;using System.Linq;using System.IO;class Program{static private Magatro M = new Magatro();static private void Main(string[]args){M.Scan();M.Solve();}}public class Scanner{private string[] S;private int Index;private char Separator;public Scanner(char separator = ' '){Index = 0;Separator = separator;}private string[] Line(){return Console.ReadLine().Split(Separator);}public string Next(){string result;if (S == null || Index >= S.Length){S = Line();Index = 0;}result = S[Index];Index++;return result;}public int NextInt(){return int.Parse(Next());}public double NextDouble(){return double.Parse(Next());}public long NextLong(){return long.Parse(Next());}}public class Magatro{private int N;private int[] A, B;public void Scan(){Scanner sc = new Scanner();N = sc.NextInt();A = new int[N];B = new int[N];for (int i = 0; i < N; i++){A[i] = sc.NextInt();}for (int i = 0; i < N; i++){B[i] = sc.NextInt();}}public void Solve(){int[] temp = new int[N];for (int i = 0; i < N; i++){temp[i] = i;}List<int[]> AList = new List<int[]>(), BList = new List<int[]>();int[] a = new int[N];int[] b = new int[N];for (int i = 0; i < N; i++){a[i] = A[temp[i]];b[i] = B[temp[i]];}AList.Add(a);BList.Add(b);while (next_permutation(temp)){// Console.WriteLine(string.Join(" ", temp));a = new int[N];b = new int[N];for (int i = 0; i < N; i++){a[i] = A[temp[i]];b[i] = B[temp[i]];}AList.Add(a);BList.Add(b);}int cnt = 0;int goukei = 0;foreach (var aa in AList){foreach (var bb in BList){goukei++;if (Q(aa, bb)) cnt++;}}Console.WriteLine((double)cnt / goukei);}private bool Q(int[] a, int[] b){int acnt = 0;int bcnt = 0;for (int i = 0; i < N; i++){if (a[i] > b[i]) acnt++;if (a[i] < b[i]) bcnt++;}if (acnt > bcnt) return true;else return false;}private bool next_permutation(int[] perm){int n = perm.Length;int k = -1;for (int i = 1; i < n; i++)if (perm[i - 1] < perm[i])k = i - 1;if (k == -1){for (int i = 0; i < n; i++)perm[i] = i;return false;}int l = k + 1;for (int i = l; i < n; i++)if (perm[k] < perm[i])l = i;int t = perm[k];perm[k] = perm[l];perm[l] = t;Array.Reverse(perm, k + 1, perm.Length - (k + 1));return true;}}