Advertisement
Guest User

Untitled

a guest
Apr 17th, 2022
34
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. //a string "ABCDEF" represents the following grid:
  4. //A B C
  5. //D E F
  6. string rotate(string s){
  7. string t = s;
  8. reverse(t.begin(), t.end());
  9. return t;
  10. }
  11. string reflect1(string s){
  12. string t = s;
  13. swap(t[0], t[2]); swap(t[3], t[5]);
  14. return t;
  15. }
  16. string reflect2(string s){
  17. string t = s;
  18. for (int i=0;i<3;i++) swap(t[i], t[3 + i]);
  19. return t;
  20. }
  21. map<string, bool> m;
  22. int main(){
  23. string grid = "ABCDEF";
  24. int num_of_ways = 0;
  25. do {
  26. if (m[grid] == 1 || m[rotate(grid)] == 1 || m[reflect1(grid)] == 1 || m[reflect2(grid)] == 1){
  27. // if any of the rotations or reflections are counted already
  28. continue;
  29. } else {
  30. // otherwise
  31. num_of_ways++;
  32. m[grid] = 1;
  33. }
  34. } while (next_permutation(grid.begin(), grid.end()));
  35. cout << "Number of ways is " << num_of_ways << endl;
  36. }
Advertisement
RAW Paste Data Copied
Advertisement