結果
| 問題 | 
                            No.199 星を描こう
                             | 
                    
| コンテスト | |
| ユーザー | 
                             izuru_matsuura
                         | 
                    
| 提出日時 | 2016-11-15 17:33:50 | 
| 言語 | D  (dmd 2.109.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 2,133 bytes | 
| コンパイル時間 | 1,743 ms | 
| コンパイル使用メモリ | 152,564 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-12 05:05:18 | 
| 合計ジャッジ時間 | 2,845 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 | 
ソースコード
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");
}
            
            
            
        
            
izuru_matsuura