Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- //using CodEx;
- namespace ConsoleApplication1
- {
- public interface Udalost
- {
- void VykonejSe(Park park);
- int Priorita();
- }
- public class Park
- {
- public static char[] mezery = { ' ' };
- public SortedList<int, List<Udalost>> kalendar;
- public Atrakce[] PoleAtrakci;
- public List<Clovek> seznamLidi = new List<Clovek>();
- public int cas;
- public Park()
- {
- cas = 0;
- kalendar = new SortedList<int, List<Udalost>>();
- }
- public void naplanuj(Udalost u, int cas)
- {
- if (kalendar.ContainsKey(cas))
- kalendar[cas].Add(u);
- else
- kalendar.Add(cas, new List<Udalost>() { u });
- }
- public void Odejit(Clovek clovek)
- {
- seznamLidi.Remove(clovek);
- }
- public void krok()
- {
- if (kalendar.ContainsKey(cas) == true)
- {
- List<Udalost> udalosti = kalendar[cas];
- foreach (Udalost udalost in udalosti)
- {
- if (udalost.Priorita() == 1)
- {
- udalost.VykonejSe(this);
- }
- }
- foreach (Udalost udalost in udalosti)
- {
- if (udalost.Priorita() == 2)
- {
- udalost.VykonejSe(this);
- }
- }
- }
- cas++;
- }
- }
- public class Atrakce : Udalost
- {
- //statistiky
- public int MaxFronta;
- public int PocetNavstevniku;
- public string Nazev;
- public int cena, delka, intenzita, kapacita, vstup, vystup;
- List<Clovek> Fronta = new List<Clovek>();
- public static char[] mezery = { ' ' };
- public Atrakce(Park park, string s)
- {
- string[] alk = s.Split(mezery, StringSplitOptions.RemoveEmptyEntries);
- this.Nazev = alk[0];
- this.cena = int.Parse(alk[1]);
- this.intenzita = int.Parse(alk[2]);
- this.delka = int.Parse(alk[3]);
- this.kapacita = int.Parse(alk[4]);
- this.vstup = int.Parse(alk[5]);
- this.vystup = int.Parse(alk[6]);
- }
- public void VykonejSe(Park park)
- {
- Frontovani();
- for (int i = 0; i < kapacita; i++)
- {
- if (Fronta.Count == 0)
- {
- break;
- }
- Clovek clovek = Fronta.First();
- PocetNavstevniku++;
- park.naplanuj(clovek, park.cas + this.delka);
- clovek.JdiNaAtrakci(this);
- Fronta.Remove(clovek);
- }
- park.naplanuj(this, park.cas + delka);
- }
- public void ZaradSe(Clovek clovek)
- {
- Fronta.Add(clovek);
- }
- public void Frontovani()
- {
- if (Fronta.Count > MaxFronta)
- MaxFronta = Fronta.Count;
- }
- public void VypisSe()
- {
- Console.WriteLine(Nazev + " " + PocetNavstevniku + " " + MaxFronta);
- }
- public int Priorita()
- {
- return 2;
- }
- }
- public class Clovek : Udalost
- {
- public int penize, tolerance, pozice;
- Atrakce aktualniAtrakce;
- public static char[] mezery = { ' ' };
- public Clovek(Park park, string s)
- {
- string[] alk = s.Split(mezery, StringSplitOptions.RemoveEmptyEntries);
- this.tolerance = int.Parse(alk[0]);
- this.penize = int.Parse(alk[1]);
- this.pozice = int.Parse(alk[2]);
- }
- public Clovek(int penize, int tolerance, int pozice)
- {
- this.penize = penize;
- this.tolerance = tolerance;
- this.pozice = pozice;
- aktualniAtrakce = null;
- }
- public void VykonejSe(Park park)
- {
- if (aktualniAtrakce != null)
- {
- pozice = aktualniAtrakce.vystup;
- }
- Atrakce atrakce = VyberAtrakce(park.PoleAtrakci);
- if (atrakce == null)
- {
- //Console.WriteLine("Jdu domu a je takovy cas: " + park.cas);
- park.Odejit(this);
- }
- else
- {
- //Console.WriteLine("Jdu na: " + atrakce.Nazev + "a je takovy cas: " + park.cas);
- atrakce.ZaradSe(this);
- }
- }
- public int Priorita()
- {
- return 1;
- }
- public Atrakce VyberAtrakce(Atrakce[] PoleAtrakciVyber)
- {
- int vysledek = -1;
- for (int i = 0; i < PoleAtrakciVyber.Length; i++)
- {
- if (VyhovujiciAtrakce(PoleAtrakciVyber[i]) == true)
- {
- if (vysledek == -1)
- {
- vysledek = i;
- }
- else
- {
- if (VzdalenostAtrakce(PoleAtrakciVyber[i]) < VzdalenostAtrakce(PoleAtrakciVyber[vysledek]))
- {
- vysledek = i;
- }
- }
- }
- }
- if (vysledek == -1)
- {
- return null;
- }
- else
- {
- return PoleAtrakciVyber[vysledek];
- }
- }
- public int VzdalenostAtrakce(Atrakce atrakce)
- {
- return Math.Abs(atrakce.vstup - pozice);
- }
- public void JdiNaAtrakci(Atrakce atrakce)
- {
- penize = penize - atrakce.cena;
- aktualniAtrakce = atrakce;
- }
- public bool VyhovujiciAtrakce(Atrakce atrakce)
- {
- if ((atrakce.intenzita >= tolerance) && (atrakce.cena <= penize))
- {
- return true;
- }
- return false;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Park park;
- park = new Park();
- int pocetAtrakci = int.Parse(Console.ReadLine());
- park.PoleAtrakci = new Atrakce[pocetAtrakci];
- for (int j = 0; j < pocetAtrakci; j++)
- {
- park.PoleAtrakci[j] = new Atrakce(park, Console.ReadLine());
- }
- int pocetLidi = int.Parse(Console.ReadLine());
- for (int j = 0; j < pocetLidi; j++)
- {
- park.seznamLidi.Add(new Clovek(park, Console.ReadLine()));
- }
- foreach (Clovek clovek in park.seznamLidi)
- {
- park.naplanuj(clovek, 0);
- }
- for (int i = 0; i < park.PoleAtrakci.Length; i++)
- {
- park.naplanuj(park.PoleAtrakci[i], 0);
- }
- while (park.seznamLidi.Count != 0)
- {
- park.krok();
- }
- Console.WriteLine(park.cas-1);
- for (int i = 0; i < park.PoleAtrakci.Length; i++)
- {
- park.PoleAtrakci[i].VypisSe();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment