Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- //a string "ABCDEF" represents the following grid:
- //A B C
- //D E F
- string rotate(string s){
- string t = s;
- reverse(t.begin(), t.end());
- return t;
- }
- string reflect1(string s){
- string t = s;
- swap(t[0], t[2]); swap(t[3], t[5]);
- return t;
- }
- string reflect2(string s){
- string t = s;
- for (int i=0;i<3;i++) swap(t[i], t[3 + i]);
- return t;
- }
- map<string, bool> m;
- int main(){
- string grid = "ABCDEF";
- int num_of_ways = 0;
- do {
- if (m[grid] == 1 || m[rotate(grid)] == 1 || m[reflect1(grid)] == 1 || m[reflect2(grid)] == 1){
- // if any of the rotations or reflections are counted already
- continue;
- } else {
- // otherwise
- num_of_ways++;
- m[grid] = 1;
- }
- } while (next_permutation(grid.begin(), grid.end()));
- cout << "Number of ways is " << num_of_ways << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement