結果

問題 No.245 貫け!
ユーザー eitahoeitaho
提出日時 2016-03-30 15:52:01
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 217 ms / 5,000 ms
コード長 4,908 bytes
コンパイル時間 1,142 ms
コンパイル使用メモリ 117,960 KB
実行使用メモリ 28,476 KB
最終ジャッジ日時 2024-10-02 08:11:20
合計ジャッジ時間 3,911 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
26,364 KB
testcase_01 AC 35 ms
28,356 KB
testcase_02 AC 35 ms
26,236 KB
testcase_03 AC 34 ms
26,556 KB
testcase_04 AC 35 ms
26,172 KB
testcase_05 AC 33 ms
24,372 KB
testcase_06 AC 34 ms
26,436 KB
testcase_07 AC 33 ms
24,116 KB
testcase_08 AC 36 ms
26,544 KB
testcase_09 AC 45 ms
26,164 KB
testcase_10 AC 50 ms
26,364 KB
testcase_11 AC 99 ms
26,560 KB
testcase_12 AC 217 ms
26,544 KB
testcase_13 AC 216 ms
26,416 KB
testcase_14 AC 210 ms
26,240 KB
testcase_15 AC 213 ms
26,368 KB
testcase_16 AC 213 ms
26,444 KB
testcase_17 AC 211 ms
28,476 KB
testcase_18 AC 212 ms
26,288 KB
testcase_19 AC 215 ms
26,236 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections.Generic;
using System.Diagnostics;
//using System.Numerics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        int N = Reader.Int();
        var segments = new Segment[N];
        var candPos = new HashSet<Point>();
        int ans = 0;

        for (int i = 0; i < N; i++)
        {
            var p = Reader.IntArray(4);
            segments[i] = new Segment(new Point(p[0], p[1]), new Point(p[2], p[3]));
            candPos.Add(segments[i].A);
            candPos.Add(segments[i].B);
        }
        foreach (var S in candPos)
            foreach (var T in candPos)
                if (S != T)
                {
                    var line = new Line(S, T);
                    int count = 0;
                    foreach (var seg in segments)
                        if (Intersect(line, seg)) count++;
                    ans = Math.Max(ans, count);
                }

        Console.WriteLine(ans);
    }

    public bool Intersect(Line line, Segment seg)
    {
        return (line.B - line.A).Det(seg.A - line.A) *
               (line.B - line.A).Det(seg.B - line.A) <= 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) { A = a; B = b; }
        public override string ToString() { return A + " - " + B; }
    }

    public class Segment
    {
        public Point A, B;
        public Point this[int i]
        {
            get { if (i == 0) return A; if (i == 1) return B; throw new ArgumentException(); }
        }
        public Segment(Point a, Point 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
{
    private static TextReader reader = Console.In;
    private static readonly char[] separator = { ' ' };
    private static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    private static string[] A = new string[0];
    private static int i;
    private 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 Enu.Range(0, N).Select(i => Int()).ToArray(); }
    public static int[][] IntTable(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); }
    public static string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Next()).ToArray(); }
    public static string Line() { return reader.ReadLine().Trim(); }
    private static string[] Split(string s) { return s.Split(separator, op); }
    private static string Next() { CheckNext(); return A[i++]; }
    private 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