Skip to content

Commit

Permalink
2024-08-20 월드컵
Browse files Browse the repository at this point in the history
  • Loading branch information
InSange committed Aug 20, 2024
1 parent 8026614 commit 9cff743
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions InSange/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
| 25차시 | 2024.08.10 | BFS | [Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees/) | [#25](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/87)]
| 26차시 | 2024.08.11 | 수학 | [Magic Squares In Grid](https://leetcode.com/problems/magic-squares-in-grid/) | [#26](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/89)]
| 27차시 | 2024.08.17 | 문자열 | [Number of Senior Citizens](https://leetcode.com/problems/number-of-senior-citizens/) | [#27](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/91)]
| 28차시 | 2024.08.21 | 백트래킹 | [월드컵](https://www.acmicpc.net/problem/6987) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/94)]
---

https://leetcode.com/problems/robot-collisions/
91 changes: 91 additions & 0 deletions InSange/백트래킹/6987.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include <iostream>
#include <vector>

using namespace std;

vector<vector<int>> record;
int t;
bool draw_flag, flag;
vector<pair<int, int>> game = { {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5},
{1, 2}, {1, 3}, {1, 4}, {1, 5},
{2, 3}, {2, 4}, {2, 5},
{3, 4}, {3, 5},
{4, 5} };

bool CheckPlay(int round)
{
if (round == 15)
{
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 3; j++)
{
if (record[i][j]) return false;
}
}
return true;
}

int firstTeam, secondTeam;
firstTeam = game[round].first;
secondTeam = game[round].second;

if (record[firstTeam][0] && record[secondTeam][2]) // first team win, second team lose
{
--record[firstTeam][0];
--record[secondTeam][2];
if (CheckPlay(round + 1)) return true;
++record[firstTeam][0];
++record[secondTeam][2];
}

if (record[firstTeam][1] && record[secondTeam][1]) // first team draw, second team draw
{
--record[firstTeam][1];
--record[secondTeam][1];
if (CheckPlay(round + 1)) return true;
++record[firstTeam][1];
++record[secondTeam][1];
}

if (record[firstTeam][2] && record[secondTeam][0]) // first team lose, second team win
{
--record[firstTeam][2];
--record[secondTeam][0];
if (CheckPlay(round + 1)) return true;
++record[firstTeam][2];
++record[secondTeam][0];
}

return false;
}

void Solve()
{
record.assign(6, vector<int>(3, 0));
t = 4;

while (t--)
{
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 3; j++)
{
cin >> record[i][j];
}
}

if (CheckPlay(0)) cout << 1 << " ";
else cout << 0 << " ";
}
}

int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);

Solve();

return 0;
}

0 comments on commit 9cff743

Please sign in to comment.