結果

問題 No.133 カードゲーム
ユーザー mbanmban
提出日時 2017-01-12 17:20:01
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,506 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 106,856 KB
実行使用メモリ 24,752 KB
最終ジャッジ日時 2023-08-23 08:46:49
合計ジャッジ時間 5,123 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 59 ms
20,796 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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;
    }
}
0