Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Jul 17, 2019
1 parent fe1a6e9 commit 8217524
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 0 deletions.
53 changes: 53 additions & 0 deletions myCpps/crossedLadders_UVA10566.cpp
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;
}
10 changes: 10 additions & 0 deletions myCpps/crossedLadders_UVA10566.in
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
10 changes: 10 additions & 0 deletions myCpps/crossedLadders_UVA10566.out
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
55 changes: 55 additions & 0 deletions myCpps/crossedLadders_UVA10566OJ.cpp
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;
}

76 changes: 76 additions & 0 deletions myCpps/roughRoads_UVA10356.cpp
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;
}
6 changes: 6 additions & 0 deletions myCpps/roughRoads_UVA10356.in
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
2 changes: 2 additions & 0 deletions myCpps/roughRoads_UVA10356.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Set #1
14
78 changes: 78 additions & 0 deletions myCpps/roughRoads_UVA10356OJ.cpp
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;
}

0 comments on commit 8217524

Please sign in to comment.