『はにょう5+』プレイ(10)

田中貴金属ゴールドバー純金 20g 田中貴金属発行 金地金 24金 金貨



『はにょう5+』プレイ(9)

キリン ファイア 挽きたて微糖 185g×30本




ファイア & 偽ムシャ

 フィールド・スピリットウェイストでSP減少空間にしてくるファイア。
ファイアを先に倒すとAT×4になる偽ムシャ。
どっちが厄介かというとファイアの方。
なので先にファイア倒してしまいましょう。


ジェノサイドガード

 攻性〇番の技が厄介。
特に弐番はストップの追加効果があるので、キャンセルした方がいいかも。
まぁ今回は最初っからピンチ状態なので戦闘放棄状態です。



Fire TV Stick (New モデル)

Fire TV Stick (New モデル)

Codingame『Mini sudoku solver』

「数独」を数学する -世界中を魅了するパズルの奥深い世界-


4 x 4数独を解け

 縦、横、2x2ドメインで数字が被らないようにすればいいんだから、
それぞれをスキャンして数字を調べていけばいい。


n x n数独

 これはn x n (n = m^2)数独でも対応可能なんだろうか?
100x100でも時間さえかければ今のコードで解けるものなのか?


コード
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

/**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 **/
class Solution
{
    static void Main(string[] args)
    {
        MiniSudokuSolver mss = new MiniSudokuSolver();

        mss.Solve();

        mss.Draw();
    }
}

class MiniSudokuSolver
{
    private List<int>[,] map;

    public MiniSudokuSolver()
    {
        map = new List<int>[4, 4];

        for (int y = 0; y < 4; y++)
        {
            string line = Console.ReadLine();
            for (int x = 0; x < 4; x++)
            {
                map[x, y] = new List<int>();

                int num = int.Parse(line[x].ToString());

                if (num == 0)
                {
                    map[x, y] = new List<int>() { 1, 2, 3, 4 };
                }
                else
                {
                    map[x, y] = new List<int>() { num };
                }
            }
        }
    }

    public void Solve()
    {
        bool f = false;

        while(!f)
        {
            f = true;

            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 4; x++)
                {
                    if(map[x,y].Count != 1)
                    {
                        for (int line = 0; line < 4; line++)
                        {
                            //横
                            if (line != x & map[line, y].Count == 1 & map[x, y].Contains(map[line, y][0]) == true)
                                map[x, y].Remove(map[line, y][0]);

                            //縦
                            if (line != y & map[x, line].Count == 1 & map[x, y].Contains(map[x, line][0]) == true)
                                map[x, y].Remove(map[x, line][0]);
                        }

                        //2x2ドメイン
                        for (int dy = y/2*2; dy < y/2*2+1; dy++)
                        {
                            for (int dx = x/2*2; dx < x/2*2+1; dx++)
                            {
                                if (dx != x & dy != y)
                                {
                                    if (map[dx, dy].Count == 1 & map[x, y].Contains(map[dx, dy][0]) == true)
                                    {
                                        map[x, y].Remove(map[dx, dy][0]);
                                    }
                                }
                            }
                        }
                    }

                    //要素数2以上があれば再ループ
                    if (map[x, y].Count != 1) f = false;
                }
            }
        }
    }


    public void Draw()
    {
        for (int y = 0; y < 4; y++)
        {
            for (int x = 0; x < 4; x++)
            {
                Console.Write(map[x, y].Count == 1 ? map[x, y][0] : 0);
            }
            Console.WriteLine("");
        }
    }
}

Codingame『Boggle』

Super Big Boggle by Winning Moves [並行輸入品]


実際に商品として存在する

 何気に初めて見た。


思い違いしてた

 例えばABCDEという単語を調べる場合、
BACD
    E
という並びでもいいのかと考えてた。


 実際には上の場合はfalseになって、行ったり来たりしない
ABCD
    E
の場合だけtrueになる。
後、地味に'T'rue 'F'alseだとダメで't'rue 'f'alseにしないといけなかったり。


再帰……

 何か久しぶりに再帰使った気がする……。
他の人のコード見るともっとスマートに再帰使ってて「えぇ…(感嘆)」状態になる。


コード
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

/**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 **/
class Solution
{
    static void Main(string[] args)
    {
        Boggle b = new Boggle();

        b.CheckWords();
        b.DrawResults();
    }
}

class Boggle
{
    private int size = 4;
    private char[,] grid;
    private bool[,] flagGrid;
    private string[] word;
    private bool[] results;

    /// <summary>
    /// コンストラクタ
    /// </summary>
    public Boggle()
    {
        this.InitGrid();
        this.ReadCheckWords();
    }

    /// <summary>
    /// 単語のチェック
    /// </summary>
    public void CheckWords()
    {
        for (int i = 0; i < this.word.Length; i++)
        {
            this.results[i] = this.IsWordOnGrid(i);
        }
    }

    /// <summary>
    /// 単語がグリッド上に存在するか
    /// </summary>
    private bool IsWordOnGrid(int i)
    {
        for (int y = 0; y < this.size; y++)
        {
            for (int x = 0; x < this.size; x++)
            {
                this.FlagInitialize();

                if (this.SearchChar(x, y, new string(this.word[i].ToCharArray())) == "")
                {
                    return true;
                }
            }
        }

        return false;
    }

    /// <summary>
    /// 文字の検索
    /// </summary>
    private string SearchChar(int x, int y, string w)
    {
        //単語の最後まで調べられている
        if (w == "") return w;

        //グリッド外
        if (x < 0 | x >= this.size) return w;
        if (y < 0 | y >= this.size) return w;

        //既に調べ済み
        if (this.flagGrid[x, y] == true) return w;

        //単語内に文字があるかどうか
        int find = w.IndexOf(this.grid[x, y]);

        //あった場合は削除
        if ( find > -1 & find == 0)
        {
            this.flagGrid[x, y] = true;
            w = w.Remove(find, 1);
        }
        else return w;

        //8方向検索
        w = this.SearchChar(x - 1, y - 1, w);
        w = this.SearchChar(x - 1, y, w);
        w = this.SearchChar(x - 1, y + 1, w);
        w = this.SearchChar(x, y - 1, w);
        w = this.SearchChar(x, y + 1, w);
        w = this.SearchChar(x + 1, y - 1, w);
        w = this.SearchChar(x + 1, y, w);
        w = this.SearchChar(x + 1, y + 1, w);

        return w;

    }

    /// <summary>
    /// 探索済みフラグを初期化する
    /// </summary>
    private void FlagInitialize()
    {
        for (int y = 0; y < this.size; y++)
        {
            for (int x = 0; x < this.size; x++)
            {
                this.flagGrid[x, y] = false;
            }
        }
    }

    /// <summary>
    /// 結果の描画
    /// </summary>
    public void DrawResults()
    {
        Console.Error.WriteLine("*** Results ***");

        for (int i = 0; i < this.results.Length; i++)
        {
            Console.WriteLine(this.results[i].ToString().ToLower());
        }
    }

    /// <summary>
    /// グリッドの初期化
    /// </summary>
    private void InitGrid()
    {
        this.grid = new char[this.size, this.size];
        this.flagGrid = new bool[this.size, this.size];

        string line;

        for (int l = 0; l < this.size; l++)
        {
            line = Console.ReadLine();
            for (int x = 0; x < this.size; x++)
            {
                this.grid[x, l] = line[x];
            }
        }

    }

    /// <summary>
    /// 調べる単語の読み込み
    /// </summary>
    private void ReadCheckWords()
    {
        int n = int.Parse(Console.ReadLine());

        this.word = new string[n];
        this.results = new bool[n];

        for (int i = 0; i < n; i++)
        {
            word[i] = Console.ReadLine();
        }
    }
}