【AOJ 2699】Koto Municipal Subway
問題
Koto Municipal Subway | Aizu Online Judge
方針
データセットの制約を見た上で全通り試すことにした.
コード
#include <iostream> #include <algorithm> #include <cmath> #include <cstdio> using namespace std; signed main(){ int D, E; while(scanf("%d %d", &D, &E), D || E){ double ans=1000.0; for(int x = 0 ; x <= 100; x++){ for(int y = 0 ; y <= 100 ; y++){ if(x + y == D){ ans = min(ans, fabs(sqrt(x * x + y * y) - E)); } } } printf("%.10lf\n", ans); } }