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 3, 2019
1 parent 73c8e84 commit a26b923
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
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 = "getaway_UVA949"; //*
const string CPPfile = "ChineseCheckers_UVA895"; //*
//***************************************

ifstream fin(CPPfile + ".cpp");
Expand Down
21 changes: 14 additions & 7 deletions myCpps/getaway_UVA949.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ ofstream fout("getaway_UVA949.out");

struct segment
{
bool wait;
int t;
int num;
};

segment _segment(int t, int num)
segment _segment(bool wait, int t, int num)
{
segment temp{t, num}; return temp;
segment temp{wait, t, num}; return temp;
}

bool g0(int x, int y, int nx, int ny)
Expand Down Expand Up @@ -79,8 +80,8 @@ int main()
pass[t] = turn(x, y, nx, ny);
}

queue<segment> q; q.push(_segment(0, turn(0, 0, nx, ny)));
vector<bool> visit(nx * ny, false);
queue<segment> q; q.push(_segment(false, 0, turn(0, 0, nx, ny)));
vector<int> d(nx * ny, nx * ny + 1);

//cout << nx << "," << ny << ":";

Expand All @@ -95,11 +96,17 @@ int main()
break;
}

visit[now.num] = true;
if (d[now.num] <= now.t && now.wait == false)
{
continue;
}

d[now.num] = now.t;

for (int p = 0; p <= 3; ++p)
{
segment next;
next.wait = false;
next.t = now.t + 1;
next.num = now.num + numP[p];

Expand All @@ -111,7 +118,7 @@ int main()
{
continue;
}
else if (visit[next.num] == true)
else if (d[next.num] < nx * ny + 1)
{
continue;
}
Expand All @@ -125,7 +132,7 @@ int main()

if (pass[now.t + 1] != now.num)
{
q.push(_segment(now.t + 1, now.num));
q.push(_segment(true, now.t + 1, now.num));
}
//cout << q.size() << '\n';
}
Expand Down
27 changes: 19 additions & 8 deletions myCpps/getaway_UVA949OJ.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#include <bits/stdc++.h>
#include <chrono>

using namespace std;
using namespace std::chrono;


struct segment
{
bool wait;
int t;
int num;
};
segment _segment(int t, int num)

segment _segment(bool wait, int t, int num)
{
segment temp{t, num}; return temp;
segment temp{wait, t, num}; return temp;
}

bool g0(int x, int y, int nx, int ny)
Expand Down Expand Up @@ -72,12 +76,13 @@ int main()
for (int c = 1; c <= m; ++c)
{
int t, x, y; cin >> t >> x >> y;

pass[t] = turn(x, y, nx, ny);
}

queue<segment> q; q.push(_segment(0, turn(0, 0, nx, ny)));
vector<bool> visit(nx * ny, false);
queue<segment> q; q.push(_segment(false, 0, turn(0, 0, nx, ny)));
vector<int> d(nx * ny, nx * ny + 1);


int ans = -1;
while (q.empty() == false && ans == -1)
Expand All @@ -90,11 +95,17 @@ int main()
break;
}

visit[now.num] = true;
if (d[now.num] <= now.t && now.wait == false)
{
continue;
}

d[now.num] = now.t;

for (int p = 0; p <= 3; ++p)
{
segment next;
next.wait = false;
next.t = now.t + 1;
next.num = now.num + numP[p];

Expand All @@ -106,7 +117,7 @@ int main()
{
continue;
}
else if (visit[next.num] == true)
else if (d[next.num] < nx * ny + 1)
{
continue;
}
Expand All @@ -120,7 +131,7 @@ int main()

if (pass[now.t + 1] != now.num)
{
q.push(_segment(now.t + 1, now.num));
q.push(_segment(true, now.t + 1, now.num));
}
}

Expand Down

0 comments on commit a26b923

Please sign in to comment.