結果

問題 No.455 冬の大三角
ユーザー eitahoeitaho
提出日時 2016-12-06 00:09:43
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 4,485 bytes
コンパイル時間 1,062 ms
コンパイル使用メモリ 113,164 KB
実行使用メモリ 18,176 KB
最終ジャッジ日時 2024-06-29 21:02:03
合計ジャッジ時間 4,515 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        int H = Reader.Int(), W = Reader.Int();
        var grid = Reader.StringArray(H);
        var P = new List<Point>();

        for (int y = 0; y < H; y++)
            for (int x = 0; x < W; x++)
                if (grid[y][x] == '*') P.Add(new Point(x, y));
        var line = new Line(P[0], P[1]);
        for (int y = 0, found = 0; y < H && found == 0; y++)
            for (int x = 0; x < W; x++)
                if (grid[y][x] == '-' && !OnLine(new Point(x, y), line))
                {
                    grid[y] = grid[y].Remove(x, 1).Insert(x, "*");
                    found = 1;
                    break;
                }

        Console.WriteLine(string.Join("\n", grid));
    }

    public bool OnLine(Point p, Line line)
    {
        return (line.A - p).Det(line.B - p) == 0;
    }
    public class Line
    {
        public Point A, B;
        public Point this[int i]
        {
            get { if (i == 0) return A; if (i == 1) return B; throw new ArgumentException(); }
        }
        public Line(Point a, Point b) { Debug.Assert(a != b); A = a; B = b; }
        public override string ToString() { return A + " - " + B; }
    }
    public struct Point : IEquatable<Point>, IComparable<Point>
    {
        public long X, Y;
        public Point(long x, long y) { X = x; Y = y; }
        public static Point operator +(Point a, Point b)
        {
            return new Point(a.X + b.X, a.Y + b.Y);
        }
        public static Point operator -(Point a, Point b)
        {
            return new Point(a.X - b.X, a.Y - b.Y);
        }
        public long DistSquare(Point b) { return (X - b.X) * (X - b.X) + (Y - b.Y) * (Y - b.Y); }
        public double Dist(Point b) { return Math.Sqrt(DistSquare(b)); }
        public long Dot(Point b) { return X * b.X + Y * b.Y; }
        public long Det(Point b) { return X * b.Y - Y * b.X; }
        public bool Equals(Point b) { return X == b.X && Y == b.Y; }
        public override bool Equals(object obj) { return Equals((Point)obj); }
        public static bool operator ==(Point a, Point b) { return a.Equals(b); }
        public static bool operator !=(Point a, Point b) { return !a.Equals(b); }
        public int CompareTo(Point b) { return X != b.X ? Math.Sign(X - b.X) : Math.Sign(Y - b.Y); }
        public override int GetHashCode() { return (int)(X * 100000 + Y); }
        public override string ToString() { return X + ", " + Y; }
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}
0