結果

問題 No.3005 トレミーの問題
ユーザー umezo
提出日時 2025-01-18 01:41:16
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,244 bytes
コンパイル時間 4,102 ms
コンパイル使用メモリ 277,948 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-01-18 01:41:22
合計ジャッジ時間 5,543 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>;

using pdd=pair<double,double>;

const double EPS=1e-6;
double f(pdd a,pdd b){
  double x=a.first,y=a.second,z=b.first,w=b.second;
  return sqrt((x-z)*(x-z)+(y-w)*(y-w));
}
double g(pdd a,pdd b,pdd c){
  double p=b.first-a.first,q=b.second-a.second;
  double r=c.first-a.first,s=c.second-a.second;
  return abs(p*s-r*q);
}
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  V<double> A(8);
  rep(i,8) cin>>A[i];
  pdd a,b,c,d;
  a.first=A[0],a.second=A[1];
  b.first=A[2],b.second=A[3];
  c.first=A[4],c.second=A[5];
  d.first=A[6],d.second=A[7];
  
  if(g(a,b,c)<EPS) cout<<"NO"<<endl;
  else if(g(a,b,d)<EPS) cout<<"NO"<<endl;
  else if(g(a,c,d)<EPS) cout<<"NO"<<endl;
  else if(g(b,c,d)<EPS) cout<<"NO"<<endl;
  else if(abs(f(a,b)*f(c,d)+f(a,d)*f(b,c)-f(a,c)*f(b,d))<EPS) cout<<"YES"<<endl;
  else if(abs(f(a,c)*f(b,d)+f(a,d)*f(b,c)-f(a,b)*f(c,d))<EPS) cout<<"YES"<<endl;
  else if(abs(f(a,b)*f(c,d)+f(a,c)*f(b,d)-f(a,d)*f(b,c))<EPS) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
    
  return 0;
}
0