Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Feb 13, 2019
1 parent bf64d36 commit 2b18db9
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 2 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@
"future": "cpp",
"mutex": "cpp",
"scoped_allocator": "cpp",
"typeindex": "cpp"
"typeindex": "cpp",
"cuchar": "cpp",
"resumable": "cpp",
"shared_mutex": "cpp",
"xthread": "cpp"
},
// "C_Cpp.intelliSenseEngineFallback": "Disabled",
"C_Cpp.errorSquiggles": "Enabled",
Expand Down
2 changes: 1 addition & 1 deletion myCpps/!-OJcreater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using namespace std;

//***************************************
const string CPPfile = "SumUpThePrimesTL_UVA10419"; //*
const string CPPfile = "miceAndMaze_UVA1112"; //*
//***************************************

ifstream fin(CPPfile + ".cpp");
Expand Down
139 changes: 139 additions & 0 deletions myCpps/SumUpThePrimesTL_UVA10419_Lamda.cpp
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;
}
53 changes: 53 additions & 0 deletions myCpps/miceAndMaze_UVA1112.cpp
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;
}
9 changes: 9 additions & 0 deletions myCpps/miceAndMaze_UVA1112.in
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
1 change: 1 addition & 0 deletions myCpps/miceAndMaze_UVA1112.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
55 changes: 55 additions & 0 deletions myCpps/miceAndMaze_UVA1112OJ.cpp
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;
}

61 changes: 61 additions & 0 deletions tempCode/twoDVectorFill.cpp
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;
}

0 comments on commit 2b18db9

Please sign in to comment.