Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. public static UInt64 HackerGrid2()
  2. {
  3. bool hacker = false;
  4. UInt64 sl = 0;
  5. string[] summaryRow;
  6. if (hacker)
  7. {
  8. summaryRow = Console.ReadLine().Split(' ');
  9. }
  10. else
  11. {
  12. summaryRow = new string[] { "4", "4", "3" };
  13. }
  14. UInt32 row = Convert.ToUInt32(summaryRow[0]);
  15. UInt32 col = Convert.ToUInt32(summaryRow[1]);
  16. Int32 k = Convert.ToInt32(summaryRow[2]);
  17. List<Tuple<UInt32, UInt32, UInt32>> tracks = new List<Tuple<UInt32, UInt32, UInt32>>(k);
  18. string[] rows;
  19. rows = new string[] { "2 2 3"
  20. , "3 1 4"
  21. , "4 4 4"
  22. };
  23. for (int j = 0; j < k; j++)
  24. {
  25. if (hacker)
  26. {
  27. summaryRow = Console.ReadLine().Split(' ');
  28. }
  29. else
  30. {
  31. summaryRow = rows[j].Split(' ');
  32. }
  33. UInt32 trow = Convert.ToUInt32(summaryRow[0]);
  34. UInt32 start = Convert.ToUInt32(summaryRow[1]);
  35. UInt32 end = Convert.ToUInt32(summaryRow[2]);
  36. tracks.Add(new Tuple<UInt32, UInt32, UInt32>(trow, start, end));
  37. }
  38. tracks.Sort();
  39. UInt32 lastRow = 0;
  40. UInt32 lastEnd = 0;
  41. sl = (UInt64)row * (UInt64)col;
  42. foreach (Tuple<UInt32, UInt32, UInt32> ts in tracks)
  43. {
  44. UInt32 trow = ts.Item1;
  45. UInt32 start = ts.Item2;
  46. UInt32 end = ts.Item3;
  47.  
  48. if (trow > lastRow || start > lastEnd)
  49. {
  50. sl -= end - start + 1;
  51. lastEnd = end;
  52. }
  53. else if (end > lastEnd)
  54. {
  55. sl -= end - lastEnd;
  56. lastEnd = end;
  57. }
  58. lastRow = trow;
  59. }
  60. Console.WriteLine(sl);
  61. return sl;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement