一开始看到题还以为要DFS还是BFS,后来发现完全不用。排个序,然后看看大小王能不能弥补缺口就行,但后来又发现还要排除有相同大小牌的情况。
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; while (cin >> n && n != 0) { vector<int> cards; int kingCount = 0; while (n--) { int x; cin >> x; if (x == 0) { kingCount++; } else { cards.push_back(x); } } sort(cards.begin(), cards.end()); bool lucky = true; for (int i = 1; i < cards.size(); i++) { if (cards[i] == cards[i-1]) { lucky = false; } kingCount -= cards[i] - cards[i-1] - 1; if (kingCount < 0) { lucky = false; } } if (lucky) { cout << "So Lucky!" << endl; } else { cout << "Oh My God!" << endl; } } }