Created
October 10, 2017 15:47
-
-
Save jason790228/e0c132c6939be259ae2f2e96b4da47e2 to your computer and use it in GitHub Desktop.
11518
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
#include "Dominos.h" | |
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
int test_case_number; | |
cin >> test_case_number; | |
for (int i = 0; i < test_case_number; i++) | |
{ | |
int n, m, l; | |
cin >> n >> m >> l; | |
Dominos test_case(n); | |
for (int j = 0; j < m; j++) | |
{ | |
int x, y; | |
cin >> x >> y; | |
test_case.add_rule(x, y); | |
} | |
for (int k = 0; k < l; k++) | |
{ | |
int z; | |
cin >> z; | |
test_case.add_action(z); | |
} | |
cout << test_case.paly() << endl; | |
} | |
return 0; | |
} |
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
#include "Dominos.h" | |
using namespace std; | |
int Dominos::paly() | |
{ | |
for (size_t i = 0; i < m_action.size(); i++) go(m_action[i]); | |
int result(0); | |
for (size_t i = 1; i < m_tile_status.size(); i++) | |
{ | |
if (!m_tile_status[i]) result++; | |
} | |
return result; | |
} | |
void Dominos::go(const int &tile_index) | |
{ | |
m_tile_status[tile_index] = false; | |
for (size_t i = 0; i < m_rule[tile_index].size(); i++) | |
{ | |
if (m_tile_status[m_rule[tile_index][i]]) go(m_rule[tile_index][i]); | |
} | |
} |
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
#include <vector> | |
class Dominos | |
{ | |
public: | |
Dominos(const int &tile_number) | |
{ | |
m_rule.resize(tile_number + 1); | |
m_tile_status.resize(tile_number + 1, true); | |
}; | |
void add_rule(const int &index, const int &data) { m_rule[index].push_back(data); }; | |
void add_action(const int &data) { m_action.push_back(data); }; | |
int paly(); | |
private: | |
void go(const int &tile_index); | |
private: | |
std::vector<std::vector<int>> m_rule; | |
std::vector<int> m_action; | |
std::vector<bool> m_tile_status; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
m_rule
與m_tile_status
應使用 initialization list 初始化m_tile_status
的 status 意義較模糊 (falled or stand)set
較符合定義。(順序無關,元素不應重複)m_tile_status[m_rule[tile_index][i]]
很長,建議改用 ranged for-loop。