結果

問題 No.199 星を描こう
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-11-15 17:33:50
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,133 bytes
コンパイル時間 1,493 ms
コンパイル使用メモリ 150,860 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-09-02 22:54:25
合計ジャッジ時間 3,020 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,368 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 2 ms
4,368 KB
testcase_13 AC 2 ms
4,368 KB
testcase_14 AC 2 ms
4,368 KB
testcase_15 AC 2 ms
4,372 KB
testcase_16 AC 2 ms
4,372 KB
testcase_17 AC 1 ms
4,372 KB
testcase_18 AC 2 ms
4,368 KB
testcase_19 AC 2 ms
4,368 KB
testcase_20 AC 1 ms
4,368 KB
testcase_21 AC 1 ms
4,368 KB
testcase_22 AC 1 ms
4,372 KB
testcase_23 AC 1 ms
4,372 KB
testcase_24 AC 2 ms
4,368 KB
testcase_25 AC 1 ms
4,372 KB
testcase_26 AC 2 ms
4,368 KB
testcase_27 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    //stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

immutable real EPS = 1e-7;

struct Point {
    real x, y;
    Point opBinary(string op)(in Point p) const if (op == "+" || op == "-") {
        return Point(mixin("x" ~ op ~ "p.x"), mixin("y" ~ op ~ "p.y"));
    }
    Point opBinary(string op)(real k) const if (op == "*" || op == "/") {
        return Point(mixin("x" ~ op ~ "k"), mixin("y" ~ op ~ "k"));
    }
};
real dot(in Point a, in Point b) { return a.x * b.x + a.y * b.y; }
real cross(in Point a, in Point b) { return a.x * b.y - a.y * b.x; }
real norm(in Point a) { return sqrt(dot(a, a)); }
Point rot90(in Point p) { return Point(-p.y, p.x); }
real angle(in Point a) { return atan2(a.y, a.x); }

int ccw(Point a, Point b, Point c){
    b = b - a; c = c - a;
    if (cross(b, c) > EPS) return +1; 
    if (cross(b, c) < -EPS) return -1;
    if (dot(b, c) < 0) return +2;     
    if (norm(b) < norm(c)) return -2; 
    return 0;                         
}

struct Segment {
    Point a, b;
};
bool intersects(in Segment s, in Segment t) {
    return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) < 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) < 0;
}

void main() {
    auto ps = new Point[5];
    foreach (ref p; ps) {
        readf("%s %s\n", &p.x, &p.y);
    }
    ps.sort!"a.x < b.x";
    do {
        Segment[] ss;
        foreach (int i; 0 .. 5) {
            ss ~= Segment(ps[i], ps[(i + 1) % 5]);
        }
        log(ps);
        foreach (i; 0 .. 5) {
            int c = 0;
            foreach (j; 0 .. 5) {
                if (i == j) continue;
                if (intersects(ss[i], ss[j])) {
                    log([i, j]);
                    c++;
                }
            }
            if (c != 2) goto next;
        }
        writeln("YES");
        return;
        next:;
    } while (ps.nextPermutation!"a.x < b.x");
    writeln("NO");
}
0