Aizu Online Judge(AOJ)の過去問から、その提出コードの解答例です。
・問題 "Intersection"
https://onlinejudge.u-aizu.ac.jp/problems/CGL_7_A
・円の交差判定
僕が作成、提出したコードは、以下のとおりです。
Aizu Online Judge in C++ #CGL_7_A : Intersection
/* Aizu Online Judge in C++ #CGL_7_A : Intersection https://onlinejudge.u-aizu.ac.jp/problems/CGL_7_A 提出コードの解答例 https://neguse-atama.hatenablog.com */ #include<bits/stdc++.h> using namespace std; int main(void){ double x1,y1,r1,r2,x2,y2; cin>>x1>>y1>>r1>>x2>>y2>>r2; double d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); if(r1>r2){ using std::swap; swap(r1,r2); } int ans=2; if(d>r1+r2){ ans=4; } if(d==r1+r2){ ans=3; } if(d==r2-r1){ ans=1; } if(d<r2-r1){ ans=0; } cout<<ans<<endl; return 0; }
設問の出典は、プログラミング問題のオンライン採点システム「Aizu Online Judge(AOJ)」です。
http://judge.u-aizu.ac.jp/onlinejudge/