Circles - Intersection

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_A
2円の共通接線の本数を求める問題。
高校数学の定義そのままです。
距離が自然数になる場合hypotは誤差なく自然数を返します。


#include<iostream>
#include<math.h>
int main(){
   double c1x,c1y,c2x,c2y,r1,r2;
   int ans=2;
   std::cin>>c1x>>c1y>>r1>>c2x>>c2y>>r2;
   double h=hypot(c1x-c2x,c1y-c2y);
   if(r1+r2<h){
       ans=4;
   }else if(r1+r2==h){
       ans=3;
   }else if((h+r1==r2)||(h+r2==r1)){
       ans=1;
   }else if((h+r1<r2)||(h+r2)<r1){
       ans=0;
   }
   std::cout<<ans<<"\n";
}
最終更新:2016年11月08日 08:00