38 lines
675 B
C++
38 lines
675 B
C++
|
// vim: set ts=2 sw=2 et tw=80:
|
||
|
|
||
|
#include <cassert>
|
||
|
#include <map>
|
||
|
|
||
|
class checker {
|
||
|
struct pos {
|
||
|
unsigned x;
|
||
|
unsigned y;
|
||
|
pos(unsigned x, unsigned y) : x(x), y(y) {};
|
||
|
};
|
||
|
|
||
|
unsigned c;
|
||
|
unsigned r;
|
||
|
std::map<pos, bool> map;
|
||
|
|
||
|
public:
|
||
|
checker(unsigned c, unsigned r) : c(c), r(r), map() {}
|
||
|
|
||
|
void visit(unsigned int x, unsigned int y);
|
||
|
bool visited(unsigned x, unsigned y);
|
||
|
};
|
||
|
|
||
|
void checker::visit(unsigned x, unsigned y) {
|
||
|
this->map[pos(] = true;
|
||
|
}
|
||
|
|
||
|
bool checker::visited(unsigned x, unsigned y) {
|
||
|
return this->map[x * this->c + y];
|
||
|
}
|
||
|
|
||
|
int main() {
|
||
|
checker a(10, 10);
|
||
|
a.visit(1, 1);
|
||
|
assert(a.visited(1,1));
|
||
|
assert(!a.visited(1,0));
|
||
|
}
|