結果

問題 No.455 冬の大三角
ユーザー qaz
提出日時 2017-05-20 13:10:48
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 2,111 bytes
コンパイル時間 1,553 ms
コンパイル使用メモリ 114,168 KB
実行使用メモリ 27,492 KB
最終ジャッジ日時 2024-06-30 01:15:31
合計ジャッジ時間 4,950 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 54
権限があれば一括ダウンロードができます
コンパイルメッセージ
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++) {
            string line = Console.ReadLine();
            foreach(var c in line.Select((x, j) => new { x, j })) {
                if( c.x == '*') {
                    maps.Map.Add(new Map { H = i, W = c.j });
                }
            }
        }

        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