Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- namespace ZadankaAK
- {
- class Krysztal
- {
- public int[] x = new int[3];
- public List<int> uzyteId = new List<int>();
- public Krysztal()
- {
- x[0] = 0;
- x[1] = 0;
- x[2] = 0;
- }
- public Krysztal(int aaa)
- {
- x[0] = aaa;
- }
- public void dodajId(int id)
- {
- uzyteId.Add(id);
- }
- }
- class Paliwo
- {
- public int iloscKrysztalow;
- public Paliwo()
- {
- StreamReader plik = new StreamReader("in.txt");
- iloscKrysztalow = Convert.ToInt32(Console.ReadLine());
- //iloscKrysztalow = Convert.ToInt32(plik.ReadLine());
- plik.ReadLine();
- Krysztal[] krysztaly = new Krysztal[iloscKrysztalow];
- List<Krysztal> krysztal2 = new List<Krysztal>();
- int nr = 0;
- string bufor;
- while ((bufor = plik.ReadLine()) != null)
- {
- bufor = bufor + ' ';
- Krysztal buforKrysztal = new Krysztal();
- int id = 0;
- for (int i = 0; i < bufor.Length-1; i+=2)
- {
- if (Char.IsDigit(bufor[i + 1])==true)
- {
- buforKrysztal.x[id] = (Convert.ToInt32(bufor[i]) - 48) * 10 + Convert.ToInt32(bufor[i + 1]) - 48;
- i++;
- id++;
- }
- else
- {
- buforKrysztal.x[id] = Convert.ToInt32(bufor[i]) - 48;
- id++;
- }
- }
- krysztaly[nr] = buforKrysztal;
- krysztal2.Add(buforKrysztal);
- krysztaly[nr].dodajId(nr);
- nr++;
- }
- plik.Close();
- int maks = maxTon(krysztaly);
- for(int i=maks; i>0; i--)
- {
- Console.WriteLine("Witam");
- sprawdzanie(i, krysztaly, krysztal2);
- }
- }
- public void sortowanie(Krysztal[] krysztaly)
- {
- for(int i=0; i<iloscKrysztalow; i++)
- {
- for(int j=1; j<iloscKrysztalow; j++)
- {
- int sumaG = 0, sumaD = 0;
- sumaG = krysztaly[j - 1].x[0] + krysztaly[j - 1].x[1] + krysztaly[j - 1].x[2];
- sumaD = krysztaly[j].x[0] + krysztaly[j].x[1] + krysztaly[j].x[2];
- if (sumaG < sumaD)
- {
- Krysztal bufor = new Krysztal();
- bufor = krysztaly[j];
- krysztaly[j] = krysztaly[j - 1];
- krysztaly[j - 1] = bufor;
- }
- }
- }
- }
- public int maxTon(Krysztal[] krysztaly)
- {
- int wynik = 0;
- Krysztal czek = new Krysztal();
- for (int i = 0; i < krysztaly.Length; i++)
- {
- czek.x[0] += krysztaly[i].x[0];
- czek.x[1] += krysztaly[i].x[1];
- czek.x[2] += krysztaly[i].x[2];
- }
- if (czek.x[0] < czek.x[1]) wynik = czek.x[0];
- else wynik = czek.x[1];
- if (wynik > czek.x[2]) wynik = czek.x[2];
- if (wynik > 100) wynik = 100;
- return wynik;
- }
- public bool check(Krysztal krysztal, Krysztal[] buff)
- {
- bool wynik = false;
- int x = 0, y = 0, z = 0;
- for(int i=0; i<iloscKrysztalow; i++)
- {
- if(krysztal.uzyteId.Contains(i) == true)
- {
- x += buff[i].x[0];
- y += buff[i].x[1];
- z += buff[i].x[2];
- }
- }
- //Console.WriteLine(x + " " + y + " " + z);
- if (x == y && y == z) wynik = true;
- if (wynik == true)
- {
- Console.WriteLine("Zdobyta ilosc paliwa: " + x * 3);
- Console.WriteLine("Kupione kryształy: " + krysztal.uzyteId.Count);
- }
- return wynik;
- }
- public int sprawdzanie(int maxTon, Krysztal[] buff, List<Krysztal> buff2)
- {
- List<Krysztal> krzystal2 = new List<Krysztal>();
- int czyDalej = 0;
- for(int i=0; i<buff2.Count; i++)
- {
- for(int j=0; j<iloscKrysztalow; j++)
- {
- if (buff2[i].uzyteId.Contains(j) == true) continue;
- int xd = buff2[i].x[0] + buff[j].x[0];
- if (xd > maxTon) continue;
- Krysztal dodatkowy = new Krysztal();
- for(int k=0; k<iloscKrysztalow; k++)
- {
- if (buff2[i].uzyteId.Contains(k)) dodatkowy.dodajId(k);
- }
- dodatkowy.x[0] = xd;
- krzystal2.Add(dodatkowy);
- krzystal2[krzystal2.Count - 1].dodajId(j);
- czyDalej++;
- if (xd == maxTon)
- {
- if (check(dodatkowy, buff) == true)
- {
- return 0;
- }
- continue;
- }
- }
- }
- if (czyDalej != 0) sprawdzanie(maxTon, buff, krzystal2);
- return 0;
- }
- public void wypisz(Krysztal []krysztaly)
- {
- for(int i=0; i<krysztaly.Length; i++)
- {
- Console.WriteLine(krysztaly[i].x[0] + " " + krysztaly[i].x[1] + " " + krysztaly[i].x[2]);
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Paliwo paliwo = new Paliwo();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement