-
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
a26b923
commit b61e0ea
Showing
4 changed files
with
2,707 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("ChineseCheckers_UVA895.in"); | ||
ofstream fout("ChineseCheckers_UVA895.out"); | ||
|
||
struct segment | ||
{ | ||
int y; | ||
int x; | ||
int t; | ||
|
||
bool operator<(const segment & temp) const | ||
{ | ||
if (y != temp.y) | ||
{ | ||
return y > temp.y; | ||
} | ||
else | ||
{ | ||
return x < temp.x; | ||
} | ||
} | ||
}; | ||
segment _segment(int y, int x, int t) | ||
{ | ||
segment temp{y, x, t}; return temp; | ||
} | ||
|
||
bool g(int y, int x, int yn, int xn) | ||
{ | ||
return y >= 1 && y <= yn && x >= 1 && x <= xn; | ||
} | ||
|
||
int main() | ||
{ | ||
vector<int> yP = {-1, -1, 0, 1, 1, 1, 0, -1}, | ||
xP = {0, 1, 1, 1, 0, -1, -1, -1}; | ||
|
||
int t = 0; | ||
while (true) | ||
{ | ||
int yn = 0, xn = 0; fin >> yn >> xn; | ||
if (yn + xn == 0) break; | ||
|
||
++t; | ||
if (t > 1) fout << '\n'; | ||
|
||
int p = 2 * xn; | ||
|
||
vector<vector<int>> a(yn + 1, vector<int>(xn + 1, 0)); | ||
for (int c = 1; c <= p * 2; ++c) | ||
{ | ||
int y, x; fin >> y >> x; | ||
|
||
if (c <= p) | ||
{ | ||
a[y][x] = 1; | ||
} | ||
else | ||
{ | ||
a[y][x] = 2; | ||
} | ||
} | ||
|
||
int yS, xS; fin >> yS >> xS; | ||
|
||
// fout << yS << ' ' << xS << '\n'; | ||
// for (int y = yn; y >= 1; --y) | ||
// { | ||
// for (int x = 1; x <= xn; ++x) | ||
// { | ||
// fout << a[y][x]; | ||
// } | ||
// fout << '\n'; | ||
// } | ||
|
||
vector<vector<bool>> visit(yn + 1, vector<bool>(xn + 1, false)); | ||
vector<segment> ans; | ||
queue<segment> q; q.push(_segment(yS, xS, 0)); | ||
while (q.empty() == false) | ||
{ | ||
segment now = q.front(); q.pop(); | ||
|
||
if (now.y != yS || now.x != xS) | ||
{ | ||
ans.push_back(now); | ||
} | ||
|
||
visit[now.y][now.x] = true; | ||
|
||
for (int p = 0; p <= 7; ++p) | ||
{ | ||
segment next; | ||
next.t = now.t + 1; | ||
next.y = now.y + (yP[p] * 2); | ||
next.x = now.x + (xP[p] * 2); | ||
|
||
if (yP[p] == -1) | ||
{ | ||
continue; | ||
} | ||
if (g(next.y, next.x, yn, xn) == false) | ||
{ | ||
continue; | ||
} | ||
else if (visit[next.y][next.x] == true) | ||
{ | ||
continue; | ||
} | ||
else if (a[next.y][next.x] != 0) | ||
{ | ||
continue; | ||
} | ||
else if (a[now.y + yP[p]][now.x + xP[p]] == 0) | ||
{ | ||
continue; | ||
} | ||
|
||
q.push(next); | ||
} | ||
} | ||
|
||
for (int p = 0; p <= 7; p += 2) | ||
{ | ||
segment next; | ||
next.t = 1; | ||
next.y = yS + yP[p]; | ||
next.x = xS + xP[p]; | ||
|
||
if (yP[p] == -1) | ||
{ | ||
continue; | ||
} | ||
else if (g(next.y, next.x, yn, xn) == false) | ||
{ | ||
continue; | ||
} | ||
else if (visit[next.y][next.x] == true) | ||
{ | ||
continue; | ||
} | ||
else if (a[next.y][next.x] != 0) | ||
{ | ||
continue; | ||
} | ||
|
||
ans.push_back(next); | ||
} | ||
|
||
sort(ans.begin(), ans.end()); | ||
|
||
int size = ans.size(); | ||
for (int i = 0; i <= size - 1; ++i) | ||
{ | ||
fout << ans[i].y << ' ' << ans[i].x << ' ' << ans[i].t << '\n'; | ||
} | ||
} | ||
|
||
|
||
return 0; | ||
} |
Oops, something went wrong.