Пример #1
0
 static void Main(string[] args)
 {
     StreamReader sr = new StreamReader(@"C:\GCJ\B-large.in");
     StreamWriter sw = new StreamWriter(@"C:\GCJ\B-OutputLarge.txt");
     string line = string.Empty;
     int cases = int.Parse(sr.ReadLine());
     for (int i = 0; i < cases; i++)
     {
         double cookiesPerSecond = 2.0;
         string[] text = sr.ReadLine().Split(' ').Select(x => x.Replace('.', ',')).ToArray<string>();
         double[] input = new double[3];
         for (int a = 0; a < text.Length; a++)
             input[a] = Convert.ToDouble(text[a]);
         double costOfFarm = input[0];
         double totalTempTime = 0.0;
         List<double> times = new List<double>();
         double farmsLeft = input[2] / costOfFarm;
         for (int a = 0; a < 200000; a++)
         {
             double timeToFarm = costOfFarm / cookiesPerSecond;
             times.Add(totalTempTime + (timeToFarm * farmsLeft));
             totalTempTime += timeToFarm;
             double leftTimeCookies = (input[2] / cookiesPerSecond) + totalTempTime;
             times.Add(leftTimeCookies);
             cookiesPerSecond += input[1];
         }
         string result = Convert.ToString(times.Min()).Replace(',', '.');
         sw.WriteLine(string.Format("Case #{0}: {1}", i + 1, result));
     }
     sr.Close();
     sw.Close();
 }
Пример #2
0
 public static List<int> FilterFunction(List<int> list, Func<int, bool> function)
 {
     List<int> result = new List<int>();
     foreach (int element in list)
     {
         if (function(element))
         {
             result.Add(element);
         }
     }
     return result;
 }
Пример #3
0
        public static List<int> FilterList(List<int> list, FilterDelegate f)
        {
            List<int> temp = new List<int>();

            foreach (int i in list)
            {
                if (f(i))
                {
                    temp.Add(i);
                }
            }

            return temp;
        }
Пример #4
0
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            int rows = int.Parse(input1.Split(' ').First());
            int cols = int.Parse(input1.Split(' ').ElementAt(1));
            string input;
            var array = new char[rows][];
            var listTuples = new List<Tuple<int, int>>();
            var playerCoords = new Tuple<int, int>(0,0);

            for (int i = 0; i < rows; i++)
            {
                input = Console.ReadLine();
                array[i] = input.ToCharArray();
            }

            for (int x = 0; x < rows; ++x)
            {
                for (int y = 0; y < cols; ++y)
                {
                    if (array[x][y].Equals('P'))
                    {
                        playerCoords = new Tuple<int, int>(x, y);
                    }
                }
            }

            input = Console.ReadLine();
            bool win = false;
            bool dead = false;
            int uf = 0;

            while (win == false && dead == false && uf < input.Length)
            {

                if (array[playerCoords.Item1][playerCoords.Item2] == 'B')
                {
                    dead = true;
                }

                if (!dead && !win && uf < input.Length)
                {
                    switch (input[uf])
                    {

                        case 'L':
                            if (playerCoords.Item2 > 0)
                            {
                                array[playerCoords.Item1][playerCoords.Item2] = '.';
                                array[playerCoords.Item1][playerCoords.Item2 - 1] = 'P';
                                playerCoords = new Tuple<int, int>(playerCoords.Item1, playerCoords.Item2 - 1);
                            }
                            else
                            {
                                array[playerCoords.Item1][playerCoords.Item2] = '.';
                                win = true;
                            }
                            break;
                        case 'R':
                            if (playerCoords.Item2 < cols - 1)
                            {
                                array[playerCoords.Item1][playerCoords.Item2] = '.';
                                array[playerCoords.Item1][playerCoords.Item2 + 1] = 'P';
                                playerCoords = new Tuple<int, int>(playerCoords.Item1, playerCoords.Item2 + 1);
                            }
                            else
                            {
                                array[playerCoords.Item1][playerCoords.Item2] = '.';
                                win = true;
                            }
                            break;
                        case 'U':
                            if (playerCoords.Item1 > 0)
                            {
                                array[playerCoords.Item1][playerCoords.Item2] = '.';
                                array[playerCoords.Item1 - 1][playerCoords.Item2] = 'P';
                                playerCoords = new Tuple<int, int>(playerCoords.Item1 -1, playerCoords.Item2);
                            }
                            else
                            {
                                array[playerCoords.Item1][playerCoords.Item2] = '.';
                                win = true;
                            }
                            break;
                        case 'D':
                            if (playerCoords.Item1 < rows - 1)
                            {
                                array[playerCoords.Item1][playerCoords.Item2] = '.';
                                array[playerCoords.Item1 + 1][playerCoords.Item2] = 'P';
                                playerCoords = new Tuple<int, int>(playerCoords.Item1 +1, playerCoords.Item2);
                            }
                            else
                            {
                                array[playerCoords.Item1][playerCoords.Item2] = '.';
                                win = true;
                            }
                            break;
                    }

                    for (int x = 0; x < rows; ++x)
                    {
                        for (int y = 0; y < cols; ++y)
                        {
                            if (array[x][y].Equals('B'))
                            {
                                listTuples.Add(new Tuple<int, int>(x, y));
                            }
                        }
                    }

                    foreach (var item in listTuples)
                    {
                        if (item.Item2 + 1 < cols)
                            array[item.Item1][item.Item2 + 1] = 'B';
                        if (item.Item2 - 1 >= 0)
                            array[item.Item1][item.Item2 - 1] = 'B';
                        if (item.Item1 + 1 < rows)
                            array[item.Item1 + 1][item.Item2] = 'B';
                        if (item.Item1 - 1 >= 0)
                            array[item.Item1 - 1][item.Item2] = 'B';
                    }
                }
                else
                {
                    break;
                }

                uf++;
            }

                for (int k = 0; k < rows; k++)
            {
                string result = String.Join("", array[k]);
                Console.WriteLine(result);
            }

            if (dead)
            {
                Console.WriteLine("dead: " + playerCoords.Item1 + " " + playerCoords.Item2);
            }

            if (win)
            {
                Console.WriteLine("won: " + playerCoords.Item1 + " " + playerCoords.Item2);
            }
        }