-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe1a6e9
commit 8217524
Showing
8 changed files
with
290 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("crossedLadders_UVA10566.in"); | ||
ofstream fout("crossedLadders_UVA10566.out"); | ||
|
||
const double eps = 1e-9; | ||
|
||
bool check(double m, double x, double y, double c) | ||
{ | ||
double a = sqrt(x * x - m * m), b = sqrt(y * y - m * m); | ||
double p = x * b / (a + b), q = y * a / (a + b); | ||
double k = (p + q + m) / 2; | ||
double s = sqrt(k * (k - p) * (k - q) * (k - m)); | ||
double h = 2 * s / m; | ||
|
||
return h < c; | ||
} | ||
|
||
int main() | ||
{ | ||
fout << fixed << setprecision(3); | ||
while (true) | ||
{ | ||
double x = 0.0, y = 0.0, c = 0.0; fin >> x >> y >> c; | ||
if (x + y + c == 0.0) break; | ||
|
||
double l = 0.0, r = min(x, y); | ||
while (true) | ||
{ | ||
double m = (l + r) / 2.0; | ||
|
||
if (check(m, x, y, c) == true) | ||
{ | ||
r = m; | ||
} | ||
else | ||
{ | ||
l = m; | ||
} | ||
|
||
if (abs(l - r) < eps) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
fout << l << '\n'; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
842.653 335.135 82.382 | ||
1044.966 554.664 214.831 | ||
578.973 760.657 278.621 | ||
72.161 136.305 42.074 | ||
757.777 694.590 303.629 | ||
297.933 912.611 211.828 | ||
790.013 425.682 136.183 | ||
25.797 832.651 6.752 | ||
975.680 636.157 227.987 | ||
219.747 597.023 9.082 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
322.223 | ||
479.103 | ||
336.669 | ||
37.022 | ||
394.125 | ||
111.001 | ||
390.323 | ||
24.883 | ||
550.955 | ||
219.553 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
|
||
const double eps = 1e-9; | ||
|
||
bool check(double m, double x, double y, double c) | ||
{ | ||
double a = sqrt(x * x - m * m), b = sqrt(y * y - m * m); | ||
double p = x * b / (a + b), q = y * a / (a + b); | ||
double k = (p + q + m) / 2; | ||
double s = sqrt(k * (k - p) * (k - q) * (k - m)); | ||
double h = 2 * s / m; | ||
|
||
return h < c; | ||
} | ||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
std::cin.tie(NULL); | ||
cout << fixed << setprecision(3); | ||
while (true) | ||
{ | ||
double x = 0.0, y = 0.0, c = 0.0; cin >> x >> y >> c; | ||
if (x + y + c == 0.0) break; | ||
|
||
double l = 0.0, r = min(x, y); | ||
while (true) | ||
{ | ||
double m = (l + r) / 2.0; | ||
|
||
if (check(m, x, y, c) == true) | ||
{ | ||
r = m; | ||
} | ||
else | ||
{ | ||
l = m; | ||
} | ||
|
||
if (abs(l - r) < eps) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
cout << l << '\n'; | ||
} | ||
|
||
cout.flush(); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("roughRoads_UVA10356.in"); | ||
ofstream fout("roughRoads_UVA10356.out"); | ||
|
||
const int inf = INT_MAX / 2; | ||
|
||
struct segment | ||
{ | ||
bool isEven; | ||
int u; | ||
int d; | ||
|
||
bool operator < (const segment & temp) const | ||
{ | ||
return d > temp.d; | ||
} | ||
}; | ||
segment _segment(bool isEven, int u, int d) | ||
{ | ||
segment temp{isEven, u, d}; return temp; | ||
} | ||
|
||
int main() | ||
{ | ||
int t = 0; | ||
while (true) | ||
{ | ||
int n = 0, m = 0; fin >> n >> m; | ||
if (n + m == 0) break; | ||
|
||
|
||
++t; | ||
|
||
vector<vector<int>> a(n, vector<int>(n, inf)), | ||
g(n); | ||
for (int c = 1; c <= m; ++c) | ||
{ | ||
int u, v, d; fin >> u >> v >> d; | ||
a[u][v] = d; a[v][u] = a[u][v]; | ||
g[u].push_back(v); g[v].push_back(u); | ||
} | ||
|
||
vector<vector<int>> d(n, vector<int>(2, inf)); | ||
priority_queue<segment> pq; pq.push(_segment(1, 0, 0)); | ||
while (pq.empty() == false) | ||
{ | ||
segment now = pq.top(); pq.pop(); | ||
|
||
if (now.d >= d[now.u][now.isEven]) continue; | ||
d[now.u][now.isEven] = now.d; | ||
|
||
int size = g[now.u].size(); | ||
for (int i = 0; i <= size - 1; ++i) | ||
{ | ||
int v = g[now.u][i]; | ||
|
||
pq.push(_segment(1 - now.isEven, v, now.d + a[now.u][v])); | ||
} | ||
} | ||
|
||
fout << "Set #" << t << '\n'; | ||
if (d[n - 1][1] == inf) | ||
{ | ||
fout << "?\n"; | ||
} | ||
else | ||
{ | ||
fout << d[n - 1][1] << '\n'; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
4 5 | ||
0 2 9 | ||
0 3 5 | ||
1 2 3 | ||
1 3 7 | ||
2 3 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Set #1 | ||
14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
|
||
const int inf = INT_MAX / 2; | ||
|
||
struct segment | ||
{ | ||
bool isEven; | ||
int u; | ||
int d; | ||
|
||
bool operator < (const segment & temp) const | ||
{ | ||
return d > temp.d; | ||
} | ||
}; | ||
segment _segment(bool isEven, int u, int d) | ||
{ | ||
segment temp{isEven, u, d}; return temp; | ||
} | ||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
std::cin.tie(NULL); | ||
int t = 0; | ||
while (true) | ||
{ | ||
int n = 0, m = 0; cin >> n >> m; | ||
if (n + m == 0) break; | ||
|
||
|
||
++t; | ||
|
||
vector<vector<int>> a(n, vector<int>(n, inf)), | ||
g(n); | ||
for (int c = 1; c <= m; ++c) | ||
{ | ||
int u, v, d; cin >> u >> v >> d; | ||
a[u][v] = d; a[v][u] = a[u][v]; | ||
g[u].push_back(v); g[v].push_back(u); | ||
} | ||
|
||
vector<vector<int>> d(n, vector<int>(2, inf)); | ||
priority_queue<segment> pq; pq.push(_segment(1, 0, 0)); | ||
while (pq.empty() == false) | ||
{ | ||
segment now = pq.top(); pq.pop(); | ||
|
||
if (now.d >= d[now.u][now.isEven]) continue; | ||
d[now.u][now.isEven] = now.d; | ||
|
||
int size = g[now.u].size(); | ||
for (int i = 0; i <= size - 1; ++i) | ||
{ | ||
int v = g[now.u][i]; | ||
|
||
pq.push(_segment(1 - now.isEven, v, now.d + a[now.u][v])); | ||
} | ||
} | ||
|
||
cout << "Set #" << t << '\n'; | ||
if (d[n - 1][1] == inf) | ||
{ | ||
cout << "?\n"; | ||
} | ||
else | ||
{ | ||
cout << d[n - 1][1] << '\n'; | ||
} | ||
} | ||
|
||
cout.flush(); | ||
return 0; | ||
} | ||
|