C++ Library for Competitive Programming
#include "emthrm/game/nim.hpp"
$N$ 個の山のいずれかから一つ以上を二人が交互に取り、操作できなくなった方を負けとするゲームである。
$O(N)$
名前 | 戻り値 |
---|---|
template <typename T> bool nim(const std::vector<T>& a);
|
盤面が $A$ のときのニムで先手が勝利するか。 |
https://yukicoder.me/submissions/701261
#ifndef EMTHRM_GAME_NIM_HPP_
#define EMTHRM_GAME_NIM_HPP_
#include <vector>
namespace emthrm {
template <typename T>
bool nim(const std::vector<T>& a) {
long long x = 0;
for (const T e : a) x ^= e;
return x != 0;
}
} // namespace emthrm
#endif // EMTHRM_GAME_NIM_HPP_
#line 1 "include/emthrm/game/nim.hpp"
#include <vector>
namespace emthrm {
template <typename T>
bool nim(const std::vector<T>& a) {
long long x = 0;
for (const T e : a) x ^= e;
return x != 0;
}
} // namespace emthrm