fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Threading;
  5. using System.Diagnostics;
  6.  
  7. namespace A
  8. {
  9. class Program
  10. {
  11. private const int N = 1000000;
  12.  
  13. private static void Main(string[] args)
  14. {
  15. long trash = 0;
  16. int a1, a2, b;
  17. var result0 = 0.0;
  18. var result1 = 0.0;
  19. int c, d;
  20. for (int i = 0; i < N; i++)
  21. {
  22. Randomize(out a1, out a2, out b);
  23.  
  24. var sw = Stopwatch.StartNew();
  25. c = a1 == 0 ? b : a1;
  26. d = a2 == 0 ? b : a2;
  27. sw.Stop();
  28. trash += c + d;
  29. result0 += (double)sw.ElapsedTicks;
  30.  
  31. var sw2 = Stopwatch.StartNew();
  32. c = a1 - a1 * a1 * b + b;
  33. d = a2 - a2 * a2 * b + b;
  34. sw2.Stop();
  35. trash += c + d;
  36. result1 += (double)sw2.ElapsedTicks;
  37. }
  38. Console.WriteLine(trash);
  39. Console.WriteLine("res1 = {0}", result0 / N);
  40. Console.WriteLine("res2 = {0}", result1 / N);
  41.  
  42. } // your code goes here
  43.  
  44. static void Randomize(out int a1, out int a2, out int b)
  45. {
  46. a1 = r.Next(0);
  47. a2 = r.Next(0) + 1;
  48. b = r.Next(0) + 1;
  49. }
  50.  
  51. static readonly Random r = new Random();
  52. }
  53. }
Success #stdin #stdout 1.36s 33928KB
stdin
Standard input is empty
stdout
4000000
res1 = 2.538031
res2 = 2.556118