Advertisement
Guest User

1488228322

a guest
Mar 30th, 2020
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.IO;
  5.  
  6. namespace ConsoleApp1
  7. {
  8.     class Program
  9.     {
  10.         public static ulong seed;
  11.         public static int n;
  12.         public static ulong rnd()
  13.         {
  14.             seed = (seed * 1103515245 + 12345) % (ulong)Math.Pow(2, 32);
  15.             return seed;
  16.         }
  17.         public static ulong newRnd(ulong s)
  18.         {
  19.             ulong eed = s;
  20.             for (int i = 0; i < n; i++)
  21.             {
  22.                 eed = (eed * 1103515245 + 12345) % (ulong)Math.Pow(2, 32);
  23.             }
  24.             return eed;
  25.         }
  26.  
  27.         public static ulong[] shuffle(ulong[] a, ulong s)
  28.         {
  29.             seed = s;
  30.             for (int i = 0; i < a.Length; i++)
  31.             {
  32.                 var t = rnd() % (ulong)(i + 1);
  33.                 var temp = a[i];
  34.                 a[i] = a[t];
  35.                 a[t] = temp;
  36.             }
  37.             return a;
  38.         }
  39.  
  40.         public static bool AreEqual(ulong[] a, ulong[] b1)
  41.         {
  42.             for (int i = 0; i < a.Length; i++)
  43.             {
  44.                 if (a[i] != b1[i])
  45.                 {
  46.                     return false;
  47.                 }
  48.             }
  49.             return true;
  50.         }
  51.         public static void Main()
  52.         {
  53.             StreamReader sr = new StreamReader("input.txt");
  54.             StreamWriter sw = new StreamWriter("output.txt");
  55.             n = int.Parse(sr.ReadLine());
  56.             ulong[] a = sr.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray();
  57.             ulong[] copyOfA = a.OrderBy(o => o).ToArray();
  58.             ulong key = 0;
  59.             for (ulong i = 0; i < Int32.MaxValue; i++)
  60.             {
  61.                 ulong[] b = (ulong[])copyOfA.Clone();
  62.                 b = shuffle(b, i);
  63.                 if (AreEqual(a, b))
  64.                 {
  65.                     key = i;
  66.                     break;
  67.                 }
  68.             }
  69.             sw.Write(string.Join(" ", shuffle(a,newRnd(key))));
  70.             sr.Close();
  71.             sw.Close();
  72.         }
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement