結果

問題 No.622 点と三角柱の内外判定
ユーザー ikd
提出日時 2017-12-27 21:30:02
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 1,017 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 105,824 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-12 23:16:44
合計ジャッジ時間 1,460 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.typecons, std.math;

  alias P=Tuple!(long, "x", long, "y", long, "z");
  auto abc=new P[](3);
  foreach(i; 0..3) rd(abc[i].x, abc[i].y, abc[i].z);
  P d;
  rd(d.x, d.y, d.z);

  alias V=P;
  V vectorizeAtoB(const P A, const P B){ // from:A to:B
    return V(B.x-A.x, B.y-A.y, B.z-A.z);
  }
  long dot(const V v1, const V v2){
    return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z;
  }
  int minus=0;
  foreach(i; 0..3){
    auto vd=vectorizeAtoB(abc[i], d),
         v1=vectorizeAtoB(abc[i], abc[(i-1+3)%3]),
         v2=vectorizeAtoB(abc[i], abc[(i+1)%3]);
    if(dot(vd, v1)<0L) minus++;
    if(dot(vd, v2)<0L) minus++;
  }
  
  if(minus<=1) writeln("YES");
  else writeln("NO");
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) write(e, " ");
  writeln();
}
0