Last active
August 29, 2015 14:11
-
-
Save MiSawa/5fa0ccb9bb2a2d579280 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <bits/stdc++.h> | |
using namespace std; | |
typedef complex<int> P; | |
struct adjacent{ | |
P p; | |
adjacent(const P &p) : p(p){} | |
template<typename ...Args> adjacent(const Args &...args) : p(args...){} | |
struct Iter : public forward_iterator_tag { | |
const P &p; | |
int i; | |
Iter(const P &p, const int &i) : p(p), i(i){} | |
Iter &operator++(){ ++i; return *this; } | |
friend bool operator!=(const Iter &a, const Iter &b){ | |
return a.i != b.i; } | |
P operator*(){ return p + P(i&1 ? 0 : i-1, i&1 ? i-2 : 0); } | |
}; | |
Iter begin(){ return Iter(p, 0); } | |
Iter end(){ return Iter(p, 4); } | |
}; | |
bool solve(){ | |
for(auto p : adjacent(2, 2)) cout << p << endl; | |
return true; | |
} | |
int main(){ | |
solve(); | |
return 0; | |
} |
This file contains hidden or 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 <bits/stdc++.h> | |
using namespace std; | |
typedef complex<int> P; | |
struct adjacent{ | |
P p; | |
adjacent(const P &p) : p(p){} | |
template<typename ...Args> adjacent(const Args &...args) : p(args...){} | |
struct Iter : public forward_iterator_tag { | |
const P &p; | |
int i; | |
Iter(const P &p, const int &i) : p(p), i(i){skip();} | |
void skip(){ | |
while(i != 4 and (real(**this) < 0 or imag(**this) < 0)) ++i; | |
} | |
Iter &operator++(){ | |
++i; | |
skip(); | |
return *this; | |
} | |
friend bool operator!=(const Iter &a, const Iter &b){ | |
return a.i != b.i; } | |
P operator*(){ return p + P(i&1 ? 0 : i-1, i&1 ? i-2 : 0); } | |
}; | |
Iter begin(){ return Iter(p, 0); } | |
Iter end(){ return Iter(p, 4); } | |
}; | |
bool solve(){ | |
for(auto p : adjacent(0, -1)){ | |
cout << p << endl; | |
cout.flush(); | |
} | |
return true; | |
} | |
int main(){ | |
solve(); | |
return 0; | |
} |
This file contains hidden or 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 <bits/stdc++.h> | |
#define aur auto& | |
using namespace std; | |
struct{ | |
struct Iter : public forward_iterator_tag { | |
int i; | |
Iter(const int &i) : i(i){} | |
Iter &operator++(){ ++i; return *this; } | |
friend bool operator!=(const Iter &a, const Iter &b){ | |
return a.i != b.i; | |
} | |
pair<int, int> operator*(){ | |
return make_pair(i&1 ? 0 : i-1, i&1 ? i-2 : 0); | |
} | |
}; | |
Iter begin(){ return Iter(0); } | |
Iter end(){ return Iter(4); } | |
} dirs; | |
signed main(){ | |
for(auto dir : dirs){ | |
int dx, dy; tie(dx, dy) = dir; | |
cout << dx << ", " << dy << endl; | |
} | |
return 0; | |
} | |
// vim:set foldmethod=marker commentstring=//%s: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment