Skip to content

Instantly share code, notes, and snippets.

@asi1024
Created July 12, 2014 13:34
Show Gist options
  • Save asi1024/241ead45581d59192bf9 to your computer and use it in GitHub Desktop.
Save asi1024/241ead45581d59192bf9 to your computer and use it in GitHub Desktop.
int main() {
double r;
int n;
while (cin >> r >> n, r) {
vector<double> h(60, 0.0);
auto height = h.begin() + 30;
REP(i,n) {
int xl, xr;
double y;
cin >> xl >> xr >> y;
for (int j = xl; j < xr; j++) {
height[j] = max(height[j], y);
}
}
double res = 1e5;
for (int i = -30; i < 30; i++) {
if (abs(i) >= r) continue;
double he = min(height[i-1], height[i]);
res = min(res, r - sqrt(r*r - i*i) + he);
}
cout << setprecision(10) << fixed << res << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment