Guest User

Untitled

a guest
Jul 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //using CodEx;
  6.  
  7.  
  8. namespace ConsoleApplication1
  9. {
  10. public interface Udalost
  11. {
  12. void VykonejSe(Park park);
  13. int Priorita();
  14. }
  15.  
  16. public class Park
  17. {
  18. public static char[] mezery = { ' ' };
  19. public SortedList<int, List<Udalost>> kalendar;
  20. public Atrakce[] PoleAtrakci;
  21. public List<Clovek> seznamLidi = new List<Clovek>();
  22. public int cas;
  23.  
  24. public Park()
  25. {
  26. cas = 0;
  27. kalendar = new SortedList<int, List<Udalost>>();
  28. }
  29.  
  30. public void naplanuj(Udalost u, int cas)
  31. {
  32. if (kalendar.ContainsKey(cas))
  33. kalendar[cas].Add(u);
  34. else
  35. kalendar.Add(cas, new List<Udalost>() { u });
  36. }
  37.  
  38. public void Odejit(Clovek clovek)
  39. {
  40. seznamLidi.Remove(clovek);
  41. }
  42.  
  43. public void krok()
  44. {
  45. if (kalendar.ContainsKey(cas) == true)
  46. {
  47. List<Udalost> udalosti = kalendar[cas];
  48. foreach (Udalost udalost in udalosti)
  49. {
  50. if (udalost.Priorita() == 1)
  51. {
  52. udalost.VykonejSe(this);
  53. }
  54. }
  55. foreach (Udalost udalost in udalosti)
  56. {
  57. if (udalost.Priorita() == 2)
  58. {
  59. udalost.VykonejSe(this);
  60. }
  61. }
  62. }
  63. cas++;
  64. }
  65. }
  66.  
  67. public class Atrakce : Udalost
  68. {
  69. //statistiky
  70. public int MaxFronta;
  71. public int PocetNavstevniku;
  72. public string Nazev;
  73.  
  74. public int cena, delka, intenzita, kapacita, vstup, vystup;
  75. List<Clovek> Fronta = new List<Clovek>();
  76. public static char[] mezery = { ' ' };
  77. public Atrakce(Park park, string s)
  78. {
  79. string[] alk = s.Split(mezery, StringSplitOptions.RemoveEmptyEntries);
  80. this.Nazev = alk[0];
  81. this.cena = int.Parse(alk[1]);
  82. this.intenzita = int.Parse(alk[2]);
  83. this.delka = int.Parse(alk[3]);
  84. this.kapacita = int.Parse(alk[4]);
  85. this.vstup = int.Parse(alk[5]);
  86. this.vystup = int.Parse(alk[6]);
  87.  
  88. }
  89.  
  90. public void VykonejSe(Park park)
  91. {
  92. Frontovani();
  93.  
  94. for (int i = 0; i < kapacita; i++)
  95. {
  96. if (Fronta.Count == 0)
  97. {
  98. break;
  99. }
  100. Clovek clovek = Fronta.First();
  101. PocetNavstevniku++;
  102. park.naplanuj(clovek, park.cas + this.delka);
  103. clovek.JdiNaAtrakci(this);
  104. Fronta.Remove(clovek);
  105. }
  106. park.naplanuj(this, park.cas + delka);
  107. }
  108. public void ZaradSe(Clovek clovek)
  109. {
  110. Fronta.Add(clovek);
  111. }
  112.  
  113. public void Frontovani()
  114. {
  115. if (Fronta.Count > MaxFronta)
  116. MaxFronta = Fronta.Count;
  117. }
  118. public void VypisSe()
  119. {
  120. Console.WriteLine(Nazev + " " + PocetNavstevniku + " " + MaxFronta);
  121. }
  122.  
  123. public int Priorita()
  124. {
  125. return 2;
  126. }
  127. }
  128.  
  129. public class Clovek : Udalost
  130. {
  131. public int penize, tolerance, pozice;
  132. Atrakce aktualniAtrakce;
  133. public static char[] mezery = { ' ' };
  134.  
  135. public Clovek(Park park, string s)
  136. {
  137. string[] alk = s.Split(mezery, StringSplitOptions.RemoveEmptyEntries);
  138. this.tolerance = int.Parse(alk[0]);
  139. this.penize = int.Parse(alk[1]);
  140. this.pozice = int.Parse(alk[2]);
  141. }
  142.  
  143. public Clovek(int penize, int tolerance, int pozice)
  144. {
  145. this.penize = penize;
  146. this.tolerance = tolerance;
  147. this.pozice = pozice;
  148. aktualniAtrakce = null;
  149. }
  150.  
  151. public void VykonejSe(Park park)
  152. {
  153. if (aktualniAtrakce != null)
  154. {
  155. pozice = aktualniAtrakce.vystup;
  156. }
  157.  
  158. Atrakce atrakce = VyberAtrakce(park.PoleAtrakci);
  159. if (atrakce == null)
  160. {
  161. //Console.WriteLine("Jdu domu a je takovy cas: " + park.cas);
  162. park.Odejit(this);
  163. }
  164. else
  165. {
  166. //Console.WriteLine("Jdu na: " + atrakce.Nazev + "a je takovy cas: " + park.cas);
  167. atrakce.ZaradSe(this);
  168. }
  169.  
  170.  
  171. }
  172.  
  173. public int Priorita()
  174. {
  175. return 1;
  176. }
  177.  
  178. public Atrakce VyberAtrakce(Atrakce[] PoleAtrakciVyber)
  179. {
  180. int vysledek = -1;
  181. for (int i = 0; i < PoleAtrakciVyber.Length; i++)
  182. {
  183. if (VyhovujiciAtrakce(PoleAtrakciVyber[i]) == true)
  184. {
  185. if (vysledek == -1)
  186. {
  187. vysledek = i;
  188. }
  189. else
  190. {
  191. if (VzdalenostAtrakce(PoleAtrakciVyber[i]) < VzdalenostAtrakce(PoleAtrakciVyber[vysledek]))
  192. {
  193. vysledek = i;
  194. }
  195. }
  196. }
  197. }
  198. if (vysledek == -1)
  199. {
  200. return null;
  201. }
  202. else
  203. {
  204. return PoleAtrakciVyber[vysledek];
  205. }
  206. }
  207. public int VzdalenostAtrakce(Atrakce atrakce)
  208. {
  209. return Math.Abs(atrakce.vstup - pozice);
  210. }
  211. public void JdiNaAtrakci(Atrakce atrakce)
  212. {
  213. penize = penize - atrakce.cena;
  214. aktualniAtrakce = atrakce;
  215.  
  216. }
  217.  
  218. public bool VyhovujiciAtrakce(Atrakce atrakce)
  219. {
  220. if ((atrakce.intenzita >= tolerance) && (atrakce.cena <= penize))
  221. {
  222. return true;
  223. }
  224. return false;
  225. }
  226. }
  227. class Program
  228. {
  229. static void Main(string[] args)
  230. {
  231. Park park;
  232. park = new Park();
  233. int pocetAtrakci = int.Parse(Console.ReadLine());
  234. park.PoleAtrakci = new Atrakce[pocetAtrakci];
  235. for (int j = 0; j < pocetAtrakci; j++)
  236. {
  237. park.PoleAtrakci[j] = new Atrakce(park, Console.ReadLine());
  238. }
  239. int pocetLidi = int.Parse(Console.ReadLine());
  240. for (int j = 0; j < pocetLidi; j++)
  241. {
  242. park.seznamLidi.Add(new Clovek(park, Console.ReadLine()));
  243. }
  244.  
  245. foreach (Clovek clovek in park.seznamLidi)
  246. {
  247. park.naplanuj(clovek, 0);
  248. }
  249. for (int i = 0; i < park.PoleAtrakci.Length; i++)
  250. {
  251. park.naplanuj(park.PoleAtrakci[i], 0);
  252. }
  253. while (park.seznamLidi.Count != 0)
  254. {
  255. park.krok();
  256. }
  257. Console.WriteLine(park.cas-1);
  258. for (int i = 0; i < park.PoleAtrakci.Length; i++)
  259. {
  260. park.PoleAtrakci[i].VypisSe();
  261. }
  262. }
  263. }
  264. }
Add Comment
Please, Sign In to add comment