Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Collections.Generic;
- namespace _07.Cubes
- {
- public class Cubes
- {
- const int edges = 12;
- //static CubeSet<Cube> cubes = new CubeSet<Cube>();
- static HashSet<Cube> cubes1 = new HashSet<Cube>();
- public static int allCubes = 0;
- static void Main()
- {
- //int[] set = new int[edges] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 };
- //int[] set = new int[edges] { 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3 };
- int[] set = ReadInput();
- int uniqueEdgeConfiguration = FeedEdgeColors(set);
- Console.WriteLine(uniqueEdgeConfiguration);
- }
- static int[] ReadInput()
- {
- int[] sticks = new int[edges];
- string[] sticksString = Console.ReadLine().Split(' ');
- for (int i = 0; i < edges; i++)
- {
- sticks[i] = int.Parse(sticksString[i]);
- }
- return sticks;
- }
- public static int FeedEdgeColors(int[] set)
- {
- //cubes.Clear();
- allCubes = 0;
- OccurrencesCounter<int> setCounter = new OccurrencesCounter<int>();
- for (var i = 0; i < set.Length; i++)
- {
- setCounter.Add(set[i]);
- }
- int[] arr = new int[set.Length];
- bool[] busy = new bool[set.Length];
- permute(setCounter, set.Length, 0, 0, -1, arr, busy);
- return allCubes;
- //return cubes.Count;
- }
- static void permute(OccurrencesCounter<int> set, int n, int numberIndex, int numberOccurenceIndex, int numberLastIndexPlacement, int[] arr, bool[] busy)
- {
- if (numberIndex >= set.Count)
- {
- int[] edges = new int[Cube.NUM_EDGES];
- Array.Copy(arr, edges, Cube.NUM_EDGES);
- Cube cube = new Cube(edges);
- AddCube(cube);
- }
- else
- {
- KeyValuePair<int, int> currNumber = set[numberIndex];
- if (numberOccurenceIndex >= currNumber.Value)
- {
- permute(set, n, numberIndex + 1, 0, -1, arr, busy);
- }
- else
- {
- var start = Math.Max(numberOccurenceIndex, numberLastIndexPlacement);
- var end = n + numberOccurenceIndex - currNumber.Value + 1;
- for (var i = start; i < end; i++)
- {
- if (busy[i]) continue;
- arr[i] = currNumber.Key;
- busy[i] = true;
- permute(set, n, numberIndex, numberOccurenceIndex + 1, i, arr, busy);
- busy[i] = false;
- }
- }
- }
- }
- static void AddCube(Cube cube)
- {
- if (cubes1.Contains(cube))
- {
- return;
- }
- for (var i = 0; i < 4; i++)
- {
- cube.RotateX();
- for (var ii = 0; ii < 4; ii++)
- {
- cube.RotateY();
- for (var iii = 0; iii < 4; iii++)
- {
- cube.RotateZ();
- cubes1.Add(new Cube(cube));
- }
- }
- }
- allCubes++;
- //cubes.Add(cube);
- }
- private static void Print(int[] array)
- {
- Console.WriteLine("{{ {0} }}", string.Join(", ", array));
- }
- }
- public class Cube : IEqualityComparer<Cube>
- {
- public const int NUM_EDGES = 12;
- public int[] edges = new int[NUM_EDGES];
- public Cube(int[] arr)
- {
- edges = arr;
- }
- public Cube(Cube cube)
- {
- Array.Copy(cube.edges, edges, NUM_EDGES);
- }
- public int GetHashCode(Cube obj)
- {
- int result = 0;
- return result;
- }
- public override int GetHashCode()
- {
- int result = GetHashCode(this);
- return result;
- }
- public override string ToString()
- {
- StringBuilder str = new StringBuilder();
- str.Append(string.Join("", edges));
- return str.ToString();
- }
- public override bool Equals(object obj)
- {
- return Equals(obj as Cube);
- }
- public bool Equals(Cube other)
- {
- bool result = Equals(this, other);
- return result;
- }
- public bool Equals(Cube item1, Cube item2)
- {
- for (int i = 0; i < Cube.NUM_EDGES; i++)
- {
- if (!item1.edges[i].Equals(item2.edges[i]))
- {
- return false;
- }
- }
- return true;
- /*
- bool equal = false;
- for (var i = 0; i < 4 && !equal; i++)
- {
- RotateX();
- if (Equal(item1.edges, item2.edges))
- {
- equal = true;
- }
- for (var ii = 0; ii < 4 && !equal; ii++)
- {
- RotateY();
- if (Equal(item1.edges, item2.edges))
- {
- equal = true;
- }
- for (var iii = 0; iii < 4 && !equal; iii++)
- {
- RotateZ();
- if (Equal(item1.edges, item2.edges))
- {
- equal = true;
- }
- }
- }
- }
- return equal;
- * */
- }
- private bool Equal(int[] arr1, int[] arr2)
- {
- for (var i = 0; i < arr1.Length; i++)
- {
- if (arr1[i] != arr2[i])
- {
- return false;
- }
- }
- return true;
- }
- public void RotateX()
- {
- int[] newEdges = new int[]
- {
- edges[4], edges[3], edges[5], edges[10],
- edges[8], edges[11], edges[2], edges[0],
- edges[7], edges[1], edges[9], edges[6]
- };
- edges = newEdges;
- }
- public void RotateY()
- {
- int[] newEdges = new int[]
- {
- edges[8], edges[7], edges[0], edges[4],
- edges[10], edges[3], edges[1], edges[9],
- edges[11], edges[6], edges[5], edges[2]
- };
- edges = newEdges;
- }
- public void RotateZ()
- {
- int[] newEdges = new int[]
- {
- edges[1], edges[2], edges[3], edges[0],
- edges[7], edges[4], edges[5], edges[6],
- edges[9], edges[11], edges[8], edges[10]
- };
- edges = newEdges;
- }
- }
- public class CubeSet<T>
- {
- public CubeSet()
- {
- list = new List<T>();
- }
- public CubeSet(int cap)
- {
- list = new List<T>(cap);
- }
- public int Count
- {
- private set
- {
- }
- get
- {
- return list.Count;
- }
- }
- public int Capacity
- {
- private set { }
- get { return list.Capacity; }
- }
- private List<T> list;
- public void Add(T cube)
- {
- if (!Contains(cube))
- {
- list.Add(cube);
- }
- }
- public void Clear()
- {
- list.Clear();
- }
- private bool Contains(T cube)
- {
- bool contains = false;
- for (var i = 0; i < list.Count; i++)
- {
- if (list[i].Equals(cube))
- {
- contains = true;
- break;
- }
- }
- return contains;
- }
- public T this[int index]
- {
- set
- {
- }
- get
- {
- return list[index];
- }
- }
- }
- public class OccurrencesCounter<T>
- {
- public class ListNode<T>
- {
- public T Value { get; private set; }
- public int OccurrencesCount { get; set; }
- public ListNode<T> NextNode { get; set; }
- public ListNode()
- {
- }
- public ListNode(T value, ListNode<T> next)
- {
- this.Value = value;
- this.NextNode = next;
- this.OccurrencesCount = 0;
- }
- }
- private ListNode<T> Head;
- private ListNode<T> Tail;
- public int Count { get; private set; }
- public void Add(T value)
- {
- if (this.Count == 0)
- {
- var node = new ListNode<T>(value, null);
- node.OccurrencesCount++;
- this.Head = node;
- this.Tail = node;
- this.Count++;
- }
- else
- {
- bool found = false;
- ListNode<T> temp = null;
- for (var i = 0; i < this.Count; i++)
- {
- if (i == 0) temp = this.Head;
- if (value.Equals(temp.Value))
- {
- temp.OccurrencesCount++;
- found = true;
- break;
- }
- temp = temp.NextNode;
- }
- if (found == false)
- {
- var node = new ListNode<T>(value, null);
- node.OccurrencesCount++;
- this.Tail.NextNode = node;
- this.Tail = node;
- this.Count++;
- }
- }
- }
- public Dictionary<T, int> ToDictionary()
- {
- Dictionary<T, int> dict = new Dictionary<T, int>();
- ListNode<T> temp = null;
- for (var i = 0; i < this.Count; i++)
- {
- if (i == 0)
- {
- temp = this.Head;
- }
- dict[temp.Value] = temp.OccurrencesCount;
- temp = temp.NextNode;
- }
- return dict;
- }
- public KeyValuePair<T, int> this[int index]
- {
- get
- {
- if (index >= this.Count)
- {
- throw new IndexOutOfRangeException("OccurrencesCounter indexer problem.");
- }
- ListNode<T> temp = null;
- for (var i = 0; i < this.Count; i++)
- {
- if (i == 0)
- {
- temp = this.Head;
- }
- if (i == index)
- {
- return new KeyValuePair<T, int>(temp.Value, temp.OccurrencesCount);
- }
- temp = temp.NextNode;
- }
- return new KeyValuePair<T, int>();
- }
- }
- public override string ToString()
- {
- StringBuilder str = new StringBuilder();
- ListNode<T> temp = new ListNode<T>();
- for (var i = 0; i < this.Count; i++)
- {
- if (i == 0)
- {
- temp = this.Head;
- }
- str.Append(string.Format("{0} => {1}\n", temp.Value, temp.OccurrencesCount));
- temp = temp.NextNode;
- }
- return str.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement