-
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
bf64d36
commit 2b18db9
Showing
8 changed files
with
324 additions
and
2 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
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
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,139 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("SumUpThePrimesTL_UVA10419.in"); | ||
ofstream fout("SumUpThePrimesTL_UVA10419.out"); | ||
|
||
|
||
const int maxP = 300; | ||
|
||
bool dp[150][1001][15]; | ||
|
||
// vector<vector<vector<bool>>> dp(150,vector<vector<bool>>(1001,vector<bool>(15,true))); | ||
// const vector<vector<vector<bool>>> dpTemp(150,vector<vector<bool>>(1001,vector<bool>(15,true))); | ||
|
||
bool compare(int x, int y) | ||
{ | ||
stringstream ss1; | ||
stringstream ss2; | ||
ss1 << x; | ||
ss2 << y; | ||
return ss1.str() < ss2.str(); | ||
} | ||
|
||
bool solve(int i, int s, int c, int x, int t, vector<int> & path, vector<int> & primes) | ||
{ | ||
int sizeP = primes.size(); | ||
|
||
if (i == primes.size()) | ||
{ | ||
return false; | ||
} | ||
else if (c == t) | ||
{ | ||
if (s == x) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
else if (s >= x) | ||
{ | ||
return false; | ||
} | ||
else if (dp[i][s][c] == false) | ||
{ | ||
return false; | ||
} | ||
|
||
path[c] = primes[i]; | ||
if (solve(i + 1, s + primes[i], c + 1, x, t, path, primes) == true) | ||
{ | ||
return true; | ||
} | ||
else if (solve(i + 1, s, c, x, t, path, primes) == true) | ||
{ | ||
return true; | ||
} | ||
|
||
dp[i][s][c] = false; | ||
return false; | ||
} | ||
|
||
int main() | ||
{ | ||
vector<bool> isPrime(maxP + 1, true); | ||
isPrime[0] = false, isPrime[1] = false; | ||
vector<int> primes; | ||
|
||
for (int i = 2; i <= maxP; ++i) | ||
{ | ||
if (isPrime[i] == true) | ||
{ | ||
for (int j = i * i; j <= maxP; j += i) | ||
{ | ||
isPrime[j] = false; | ||
} | ||
} | ||
} | ||
|
||
primes.push_back(2); | ||
for (int x = 3; x <= 300; ++x) | ||
{ | ||
if (isPrime[x] == true) | ||
{ | ||
for (int c = 1; c <= 2; ++c) | ||
{ | ||
primes.push_back(x); | ||
} | ||
} | ||
} | ||
|
||
//sort(primes.begin(), primes.end(), compare); | ||
|
||
sort(primes.begin(), primes.end(), [](int x, int y) | ||
{ | ||
stringstream ss1; | ||
stringstream ss2; | ||
ss1 << x; | ||
ss2 << y; | ||
return ss1.str() < ss2.str(); | ||
}); | ||
|
||
int _case = 0, sizeP = primes.size(); | ||
|
||
while (true) | ||
{ | ||
int x = 0, t = 0; | ||
fin >> x >> t; | ||
if (x + t == 0) | ||
break; | ||
++_case; | ||
|
||
fout << "CASE " << _case << ":\n"; | ||
|
||
vector<int> path(t); | ||
//vector<vector<vector<bool>>> dp(sizeP + 1, vector<vector<bool>>(x + 1, vector<bool>(t + 1, true))); | ||
memset(dp, true, sizeof(dp)); | ||
|
||
bool ans = solve(0, 0, 0, x, t, path, primes); | ||
|
||
if (ans == false) | ||
{ | ||
fout << "No Solution.\n"; | ||
} | ||
else | ||
{ | ||
for (int i = 0; i <= t - 1; ++i) | ||
{ | ||
if (i > 0) | ||
fout << '+'; | ||
fout << path[i]; | ||
} | ||
fout << '\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,53 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("miceAndMaze_UVA1112.in"); | ||
ofstream fout("miceAndMaze_UVA1112.out"); | ||
|
||
int main() | ||
{ | ||
int testCase; fin >> testCase; | ||
for (int t = 1; t <= testCase; ++t) | ||
{ | ||
if (t > 1) fout << '\n'; | ||
|
||
int n, e, tl, m; fin >> n >> e >> tl >> m; | ||
vector<vector<int>> d(n + 1, vector<int>(n + 1, INT_MAX / 2)); | ||
|
||
for (int c = 1; c <= m; ++c) | ||
{ | ||
int u, v, dc; fin >> u >> v >> dc; | ||
d[u][v] = dc; | ||
} | ||
|
||
for (int i = 1; i <= n; ++i) | ||
{ | ||
d[i][i] = 0; | ||
} | ||
|
||
for (int k = 1; k <= n; ++k) | ||
{ | ||
for (int u = 1; u <= n; ++u) | ||
{ | ||
for (int v = 1; v <= n; ++v) | ||
{ | ||
d[u][v] = min(d[u][v], d[u][k] + d[k][v]); | ||
} | ||
} | ||
} | ||
|
||
int ans = 0; | ||
for (int i = 1; i <= n; ++i) | ||
{ | ||
if (d[i][e] <= tl) | ||
{ | ||
++ans; | ||
} | ||
} | ||
|
||
fout << ans << '\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,9 @@ | ||
1 | ||
|
||
4 | ||
3 | ||
3 | ||
2 | ||
1 2 2 | ||
2 3 1 | ||
3 4 2 |
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 @@ | ||
3 |
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; | ||
|
||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
std::cin.tie(NULL); | ||
int testCase; cin >> testCase; | ||
for (int t = 1; t <= testCase; ++t) | ||
{ | ||
if (t > 1) cout << '\n'; | ||
|
||
int n, e, tl, m; cin >> n >> e >> tl >> m; | ||
vector<vector<int>> d(n + 1, vector<int>(n + 1, INT_MAX / 2)); | ||
|
||
for (int c = 1; c <= m; ++c) | ||
{ | ||
int u, v, dc; cin >> u >> v >> dc; | ||
d[u][v] = dc; | ||
} | ||
|
||
for (int i = 1; i <= n; ++i) | ||
{ | ||
d[i][i] = 0; | ||
} | ||
|
||
for (int k = 1; k <= n; ++k) | ||
{ | ||
for (int u = 1; u <= n; ++u) | ||
{ | ||
for (int v = 1; v <= n; ++v) | ||
{ | ||
d[u][v] = min(d[u][v], d[u][k] + d[k][v]); | ||
} | ||
} | ||
} | ||
|
||
int ans = 0; | ||
for (int i = 1; i <= n; ++i) | ||
{ | ||
if (d[i][e] <= tl) | ||
{ | ||
++ans; | ||
} | ||
} | ||
|
||
cout << ans << '\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,61 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
//ifstream fin("twoDVectorFill.in"); | ||
//ofstream fout("twoDVectorFill.out"); | ||
|
||
|
||
|
||
int main2() | ||
{ | ||
//code | ||
vector<vector<int>> v(100, vector<int>(10, 0)); | ||
std::fill(v.begin(), v.end(), vector<int>(19, 5)); | ||
return 0; | ||
} | ||
|
||
void createVector() | ||
{ | ||
clock_t startT; | ||
clock_t endT; | ||
double cpu_time_used; | ||
startT = clock(); | ||
vector<vector<vector<bool>>> dp(150, vector<vector<bool>>(1001, vector<bool>(15, true))); | ||
//vector<vector<bool>> dp(150,vector<bool>(1001,true)); | ||
endT = clock(); | ||
cpu_time_used = ((double)(endT - startT)); | ||
cout << "CPU time create 150x1001x15 vector = " << cpu_time_used << endl; | ||
dp.clear(); | ||
dp.shrink_to_fit(); | ||
} | ||
|
||
void createFixArray() | ||
{ | ||
clock_t startT; | ||
clock_t endT; | ||
double cpu_time_used; | ||
startT = clock(); | ||
bool dp2[150][1001][15]; | ||
memset(dp2, true, sizeof(dp2)); | ||
endT = clock(); | ||
cpu_time_used = ((double)(endT - startT)); | ||
cout << "CPU time create 150x1001x15 fix array :" << cpu_time_used << endl; | ||
} | ||
|
||
int main() | ||
{ | ||
createVector(); | ||
//createFixArray(); | ||
clock_t startT; | ||
clock_t endT; | ||
double cpu_time_used; | ||
startT = clock(); | ||
bool dp2[150][1001][15]; | ||
memset(dp2, true, sizeof(dp2)); | ||
endT = clock(); | ||
cpu_time_used = ((double)(endT - startT)); | ||
cout << "CPU time create 150x1001x15 fix array :" << cpu_time_used << endl; | ||
|
||
return 0; | ||
} |