寝癖頭の解法

学習中の覚え書きを投稿、更新していきます。

Aizu Online Judge in C++ #CGL_7_B : Incircle of a Triangle

Aizu Online Judge(AOJ)の過去問から、その提出コードの解答例です。

・問題 "Incircle of a Triangle"
https://onlinejudge.u-aizu.ac.jp/problems/CGL_7_B
・内接円

僕が作成、提出したコードは、以下のとおりです。

Aizu Online Judge in C++ #CGL_7_B : Incircle of a Triangle
/*
Aizu Online Judge in C++ #CGL_7_B : Incircle of a Triangle
https://onlinejudge.u-aizu.ac.jp/problems/CGL_7_B
 提出コードの解答例
 https://neguse-atama.hatenablog.com
*/
#include<bits/stdc++.h>
using namespace std;
using ld=long double;
ld cx,cy,r=0,t,u,v;
int main(void){
    ld x1,x2,x3,y1,y2,y3;
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    t=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
    u=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
    v=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    cx=(t*x1+u*x2+v*x3)/(t+u+v);
    cy=(t*y1+u*y2+v*y3)/(t+u+v);
    r=sqrt((t+u-v)*(t-u+v)*(u+v-t)/(t+u+v))/2;
    cout<<setprecision(20)<<cx<<" "<<cy<<" "<<r<<endl;
    return 0;
}

設問の出典は、プログラミング問題のオンライン採点システム「Aizu Online Judge(AOJ)」です。
http://judge.u-aizu.ac.jp/onlinejudge/