fork(1) download
  1. // RUSSIAN SORTING HALVES DANILIN
  2. using System; using System.Text;
  3. class rsh
  4. { static long[] a; static long[] d;
  5. static void Main(string[] args)
  6. { int n = 1000000;
  7. var age = 1 + Math.Log(n) / Math.Log(2);
  8. Console.WriteLine(n);
  9.  
  10. a = new long[n + 1]; d = new long[n + 1];
  11.  
  12. var rand = new Random();
  13. for (int i = 1; i <= n; i++)
  14. d[i] = rand.Next(1, n);
  15.  
  16. // WRITE ON SCREEN
  17. int m = Math.Min(n, 10);
  18. for (int i = 1; i <= m; i++)
  19. Console.Write("{0} ", d[i]);
  20. Console.WriteLine();
  21.  
  22. // RUSSIAN SORTING HALVES DANILIN
  23. var start = DateTime.Now;
  24. if (age > 0)
  25. dav(1, n, 1, age);
  26. var finish = DateTime.Now;
  27.  
  28. Console.WriteLine("{0} second", (finish - start).TotalSeconds);
  29.  
  30. // WRITE ON SCREEN
  31. Console.WriteLine("[1..{0}]", m);
  32. for (int i = 1; i <= m; i++)
  33. Console.Write("{0} ", d[i]);
  34. Console.WriteLine();
  35.  
  36. // WRITE ON SCREEN
  37. Console.WriteLine("[{0}..{1}]", n - m + 1, n);
  38. for (int i = n - m + 1; i <= n; i++)
  39. Console.Write("{0} ", d[i]);
  40. Console.WriteLine();
  41. Console.WriteLine("Press any key"); Console.ReadKey();
  42. }
  43.  
  44. static void dav(int ab, int yz, int part, double age)
  45. { if (yz - ab < 1) return;
  46.  
  47. long summa = 0;
  48. for (int i = ab; i <= yz; i++)
  49. summa = summa + d[i];
  50.  
  51. double middle = summa / (yz - ab + 1.0);
  52. var abc = ab - 1; var xyz = yz + 1;
  53.  
  54. for (int i = ab; i <= yz; i++)
  55. if (d[i] < middle)
  56. { abc = abc + 1; a[abc] = d[i];
  57. }
  58. else
  59. { xyz = xyz - 1; a[xyz] = d[i];
  60. }
  61.  
  62. for (int i = ab; i <= yz; i++)
  63. d[i] = a[i];
  64.  
  65. if (part < age)
  66. { if (abc >= ab) dav(ab, abc, part + 1, age);
  67. if (xyz <= yz) dav(xyz, yz, part + 1, age);
  68. }
  69. return; }}
Runtime error #stdin #stdout #stderr 0.53s 52828KB
stdin
Standard input is empty
stdout
1000000
91834 674286 599269 167218 834221 649941 946001 564942 973997 189608 
0.425543 second
[1..10]
1 2 2 2 2 2 3 4 5 8 
[999991..1000000]
999983 999986 999987 999988 999990 999992 999992 999995 999997 999999 
Press any key
stderr
Unhandled exception. System.InvalidOperationException: Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read.
   at System.ConsolePal.ReadKey(Boolean intercept)
   at System.Console.ReadKey()
   at rsh.Main(String[] args) in /home/XUikTs/Project/Program.cs:line 41