結果

問題 No.133 カードゲーム
ユーザー bluemegane
提出日時 2020-09-10 20:31:49
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 1,667 bytes
コンパイル時間 2,649 ms
コンパイル使用メモリ 109,952 KB
実行使用メモリ 19,968 KB
最終ジャッジ日時 2024-12-23 23:08:19
合計ジャッジ時間 4,407 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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.

ソースコード

diff #

using System.Linq;
using System.Collections.Generic;
using System;

public static class Permi
{
    public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> items, int? k = null)
    {
        if (k == null) k = items.Count();
        if (k == 0) yield return Enumerable.Empty<T>();
        else
        {
            var i = 0;
            foreach (var x in items)
            {
                var xs = items.Where((_, index) => i != index);
                foreach (var c in Perm(xs, k - 1))
                    yield return c.Before(x);
                i++;
            }
        }
    }
    public static IEnumerable<T> Before<T>(this IEnumerable<T> items, T first)
    {
        yield return first;
        foreach (var i in items) yield return i;
    }
}

public class Hello
{
    public static int[] b;
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        b = Array.ConvertAll(line, int.Parse);
        getAns(n, a);
    }
    static bool IsWin(int n, int[] a)
    {
        var count = 0;
        for (int i = 0; i < n; i++)
        {
            if (a[i] > b[i]) count++;
        }
        return count > n - count;
    }
    static void getAns(int n, int[] a)
    {
        var count = 0;
        var total = 0;
        var a2 = a.Perm();
        foreach (var x in a2)
        {
            total++;
            var c = x.ToArray();
            if (IsWin(n, c)) count++;
        }
        Console.WriteLine((double)count / total);
    }
}
0