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 9, 2019
1 parent 5c6bc2a commit 12398a7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 30 deletions.
15 changes: 10 additions & 5 deletions myCpps/fill_UVA10603.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,26 @@ int main()
{
int a, b, c, d; fin >> a >> b >> c >> d;

vector<vector<vector<int>>> dp(a + 1, vector<vector<int>>(b + 1, vector<int>(c + 1, inf)));
dp[0][0][c] = 0;
vector<vector<int>> dp(a + 1, vector<int>(b + 1, inf));
dp[0][0] = 0;

vector<int> ans(max(a, max(b, max(c, d))) + 1, inf);
priority_queue<segment> pq; pq.push(_segment(0, 0, c, 0));
while (pq.empty() == false)
{
segment now = pq.top(); pq.pop();

if (now.total >= dp[now.j1][now.j2][now.j3] && now.total > 0)
if (now.total >= dp[now.j1][now.j2] && now.total > 0)
{
continue;
}

dp[now.j1][now.j2][now.j3] = now.total;
dp[now.j1][now.j2] = now.total;

ans[now.j1] = min(ans[now.j1], now.total);
ans[now.j2] = min(ans[now.j2], now.total);
ans[now.j3] = min(ans[now.j3], now.total);


segment temp;

if (now.j1 > 0)
Expand All @@ -82,13 +81,15 @@ int main()
{
temp = now; // 1 -> 2
temp.total += pour(a, temp.j1, b, temp.j2);

pq.push(temp);
}

if (now.j3 < c)
{
temp = now; // 1 -> 3
temp.total += pour(a, temp.j1, c, temp.j3);

pq.push(temp);
}
}
Expand All @@ -99,13 +100,15 @@ int main()
{
temp = now; // 2 -> 1
temp.total += pour(b, temp.j2, a, temp.j1);

pq.push(temp);
}

if (now.j3 < c)
{
temp = now; // 2 -> 3
temp.total += pour(b, temp.j2, c, temp.j3);

pq.push(temp);
}
}
Expand All @@ -116,13 +119,15 @@ int main()
{
temp = now; // 3 -> 1
temp.total += pour(c, temp.j3, a, temp.j1);

pq.push(temp);
}

if (now.j2 < b)
{
temp = now; // 3 -> 2
temp.total += pour(c, temp.j3, b, temp.j2);

pq.push(temp);
}
}
Expand Down
77 changes: 52 additions & 25 deletions myCpps/fill_UVA10603OJ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,56 +53,83 @@ int main()
{
int a, b, c, d; cin >> a >> b >> c >> d;

vector<vector<vector<int>>> dp(a + 1, vector<vector<int>>(b + 1, vector<int>(c + 1, inf)));
dp[0][0][c] = 0;
vector<vector<int>> dp(a + 1, vector<int>(b + 1, inf));
dp[0][0] = 0;

vector<int> ans(max(a, max(b, max(c, d))) + 1, inf);
priority_queue<segment> pq; pq.push(_segment(0, 0, c, 0));
while (pq.empty() == false)
{
segment now = pq.top(); pq.pop();

if (now.total >= dp[now.j1][now.j2][now.j3] && now.total > 0) continue;
dp[now.j1][now.j2][now.j3] = now.total;
if (now.total >= dp[now.j1][now.j2] && now.total > 0)
{
continue;
}

dp[now.j1][now.j2] = now.total;

ans[now.j1] = min(ans[now.j1], now.total);
ans[now.j2] = min(ans[now.j2], now.total);
ans[now.j3] = min(ans[now.j3], now.total);


segment temp;

if (now.j1 > 0)
{
temp = now; // 1 -> 2
temp.total += pour(a, temp.j1, b, temp.j2);
pq.push(temp);
if (now.j2 < b)
{
temp = now; // 1 -> 2
temp.total += pour(a, temp.j1, b, temp.j2);

pq.push(temp);
}

temp = now; // 1 -> 3
temp.total += pour(a, temp.j1, c, temp.j3);
pq.push(temp);
if (now.j3 < c)
{
temp = now; // 1 -> 3
temp.total += pour(a, temp.j1, c, temp.j3);

pq.push(temp);
}
}

if (now.j2 > 0)
{
temp = now; // 2 -> 1
temp.total += pour(b, temp.j2, a, temp.j1);
pq.push(temp);

temp = now; // 2 -> 3
temp.total += pour(b, temp.j2, c, temp.j3);
pq.push(temp);
if (now.j1 < a)
{
temp = now; // 2 -> 1
temp.total += pour(b, temp.j2, a, temp.j1);

pq.push(temp);
}

if (now.j3 < c)
{
temp = now; // 2 -> 3
temp.total += pour(b, temp.j2, c, temp.j3);

pq.push(temp);
}
}

if (now.j3 > 0)
{
temp = now; // 3 -> 1
temp.total += pour(c, temp.j3, a, temp.j1);
pq.push(temp);
if (now.j1 < a)
{
temp = now; // 3 -> 1
temp.total += pour(c, temp.j3, a, temp.j1);

pq.push(temp);
}

if (now.j2 < b)
{
temp = now; // 3 -> 2
temp.total += pour(c, temp.j3, b, temp.j2);

temp = now; // 3 -> 2
temp.total += pour(c, temp.j3, b, temp.j2);
pq.push(temp);
pq.push(temp);
}
}
}

Expand Down

0 comments on commit 12398a7

Please sign in to comment.