Skip to content

Instantly share code, notes, and snippets.

@kumar8600
Created July 11, 2014 16:56
Show Gist options
  • Save kumar8600/bebd339521dbea4b589e to your computer and use it in GitHub Desktop.
Save kumar8600/bebd339521dbea4b589e to your computer and use it in GitHub Desktop.
ICPC 国内予選 2014 C
#include <iostream>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;
int main()
{
int r; int n;
while (cin >> r >> n, r | n) {
vector<int> citySunRising(40, 0); // 0: 20
for (int i = 0; i < n; ++i) {
int xl, xr, h;
cin >> xl >> xr >> h;
for (int j = xl; j < xr; ++j) {
citySunRising[j + 20] = max(h, citySunRising[j + 20]);
}
}
double ans = DBL_MAX;
for (int i = -r; i < 0; ++i) {
ans = min(ans, r - r * sin(acos((i + 1) / (double)r)) + citySunRising[i + 20]);
}
for (int i = 0; i < r; ++i) {
ans = min(ans, r - r * sin(acos((i) / (double)r)) + citySunRising[i + 20]);
}
cout << fixed << setprecision(4) << ans << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment