結果

問題 No.455 冬の大三角
ユーザー qaz
提出日時 2017-05-20 13:03:29
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,018 bytes
コンパイル時間 1,090 ms
コンパイル使用メモリ 108,032 KB
実行使用メモリ 21,120 KB
最終ジャッジ日時 2024-09-19 00:27:04
合計ジャッジ時間 5,024 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46 WA * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Generic;
using System.Linq;

public class Program
{
    public static void Main() {
        var data = Console.ReadLine().Split(' ');
        int H = int.Parse(data[0]);
        int W = int.Parse(data[1]);

        var maps = new Maps();
        for (int i = 0; i < H; i++) {
            int w = Console.ReadLine().IndexOf('*');
            if (w >= 0) {
                maps.Map.Add(new Map { H = i, W = w });
            }
        }

        var map = maps.Search(H, W);
        if (map != null) {
            maps.Map.Add(map);
        }

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (maps.Map.Any(x => x.H == i && x.W == j)) {
                    Console.Write("*");
                }
                else {
                    Console.Write("-");
                }
            }
            Console.WriteLine();
        }
    }
}

public class Maps
{
    public List<Map> Map { get; set; }

    public Maps() {
        Map = new List<Map>();
    }

    public Map Search(int H, int W) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (IsConfirm(i, j)) {
                    return new Map { H = i, W = j };
                }
            }
        }
        return null;
    }

    public bool IsConfirm(int h, int w) {
        var slope = new List<string>();
        foreach (var item in Map) {
            slope.Add(GetSlope(item, h, w));
        }

        return slope.Count() == slope.Distinct().Count() && !slope.Any(x => x == "");
    }

    public string GetSlope(Map map, int hh, int ww) {
        decimal h = map.H - hh;
        decimal w = map.W - ww;

        if(h == 0 && w == 0) {
            return "";
        }

        if (w == 0) {
            return "∞";
        }
        if (h == 0) {
            return "0";
        }
        return (h / w).ToString();
    }
}

public class Map
{
    public int H { get; set; }
    public int W { get; set; }
}
0