Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.IO;
- namespace ConsoleApp1
- {
- class Program
- {
- public static ulong seed;
- public static int n;
- public static ulong rnd()
- {
- seed = (seed * 1103515245 + 12345) % (ulong)Math.Pow(2, 32);
- return seed;
- }
- public static ulong newRnd(ulong s)
- {
- ulong eed = s;
- for (int i = 0; i < n; i++)
- {
- eed = (eed * 1103515245 + 12345) % (ulong)Math.Pow(2, 32);
- }
- return eed;
- }
- public static ulong[] shuffle(ulong[] a, ulong s)
- {
- seed = s;
- for (int i = 0; i < a.Length; i++)
- {
- var t = rnd() % (ulong)(i + 1);
- var temp = a[i];
- a[i] = a[t];
- a[t] = temp;
- }
- return a;
- }
- public static bool AreEqual(ulong[] a, ulong[] b1)
- {
- for (int i = 0; i < a.Length; i++)
- {
- if (a[i] != b1[i])
- {
- return false;
- }
- }
- return true;
- }
- public static void Main()
- {
- StreamReader sr = new StreamReader("input.txt");
- StreamWriter sw = new StreamWriter("output.txt");
- n = int.Parse(sr.ReadLine());
- ulong[] a = sr.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray();
- ulong[] copyOfA = a.OrderBy(o => o).ToArray();
- ulong key = 0;
- for (ulong i = 0; i < Int32.MaxValue; i++)
- {
- ulong[] b = (ulong[])copyOfA.Clone();
- b = shuffle(b, i);
- if (AreEqual(a, b))
- {
- key = i;
- break;
- }
- }
- sw.Write(string.Join(" ", shuffle(a,newRnd(key))));
- sr.Close();
- sw.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement