Advertisement
Guest User

Untitled

a guest
Nov 29th, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.IO;
  4. using System.Text;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7.  
  8. /**
  9. * Save humans, destroy zombies!
  10. **/
  11.  
  12. struct ZombieToHuman
  13. {
  14. public int HumanId;
  15. public int ZombieId;
  16. public int Distance;
  17. public int TurnsToReach;
  18. }
  19.  
  20. struct AshToHuman
  21. {
  22. public int HumanId;
  23. public int Distance;
  24. public int TurnsToReach;
  25. }
  26.  
  27. struct Zombie
  28. {
  29. public int X;
  30. public int Y;
  31. public int NextX;
  32. public int NextY;
  33. }
  34.  
  35. struct Human
  36. {
  37. public int X;
  38. public int Y;
  39. }
  40.  
  41. class Player
  42. {
  43. private static int CalcDistance(int x1, int y1, int x2, int y2)
  44. {
  45. // d = sqrt( sqr(x2-x1) + sqr(y2 - y1) )
  46. return (int)Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2));
  47. }
  48. static void Main(string[] args)
  49. {
  50. string[] inputs;
  51.  
  52. // game loop
  53. while (true)
  54. {
  55. var humans = new Dictionary<int, Human>();
  56. var zombies = new Dictionary<int, Zombie>();
  57.  
  58. inputs = Console.ReadLine().Split(' ');
  59. int x = int.Parse(inputs[0]);
  60. int y = int.Parse(inputs[1]);
  61.  
  62. int humanCount = int.Parse(Console.ReadLine());
  63. for (int i = 0; i < humanCount; i++)
  64. {
  65. inputs = Console.ReadLine().Split(' ');
  66. int humanId = int.Parse(inputs[0]);
  67. int humanX = int.Parse(inputs[1]);
  68. int humanY = int.Parse(inputs[2]);
  69.  
  70. humans.Add(humanId, new Human
  71. {
  72. X = humanX,
  73. Y = humanY,
  74. });
  75. }
  76. int zombieCount = int.Parse(Console.ReadLine());
  77. for (int i = 0; i < zombieCount; i++)
  78. {
  79. inputs = Console.ReadLine().Split(' ');
  80. int zombieId = int.Parse(inputs[0]);
  81. int zombieX = int.Parse(inputs[1]);
  82. int zombieY = int.Parse(inputs[2]);
  83. int zombieXNext = int.Parse(inputs[3]);
  84. int zombieYNext = int.Parse(inputs[4]);
  85.  
  86. zombies.Add(zombieId, new Zombie
  87. {
  88. X = zombieX,
  89. Y = zombieY,
  90. NextX = zombieXNext,
  91. NextY = zombieYNext,
  92. });
  93. }
  94.  
  95. var zombiesToHumans = new List<ZombieToHuman>();
  96. var ashToHumans = new Dictionary<int, AshToHuman>();
  97.  
  98. foreach (var human in humans)
  99. {
  100. var distance = CalcDistance(human.Value.X, human.Value.Y, x, y);
  101.  
  102. ashToHumans.Add(human.Key, new AshToHuman
  103. {
  104. Distance = distance,
  105. HumanId = human.Key,
  106. TurnsToReach = (distance - 2000) / 1000,
  107. });
  108.  
  109. foreach (var zombie in zombies)
  110. {
  111. distance = CalcDistance(zombie.Value.X, zombie.Value.Y, human.Value.X, human.Value.Y);
  112.  
  113. zombiesToHumans.Add(new ZombieToHuman
  114. {
  115. Distance = distance,
  116. ZombieId = zombie.Key,
  117. HumanId = human.Key,
  118. TurnsToReach = (distance - 400) / 400,
  119. });
  120. }
  121. }
  122.  
  123. var h = zombiesToHumans.OrderBy(zh => zh.TurnsToReach).Where(zh => zh.TurnsToReach >= ashToHumans[zh.HumanId].TurnsToReach).First();
  124.  
  125. // Write an action using Console.WriteLine()
  126. // To debug: Console.Error.WriteLine("Debug messages...");
  127. Console.WriteLine("{0} {1}", zombies[h.ZombieId].NextX, zombies[h.ZombieId].NextY); // Your destination coordinates
  128. }
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement