vstoyanov

3-та Задача

Oct 2nd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Olimpic
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int numberTests = int.Parse(Console.ReadLine());
  12.  
  13.             for (int i = 0; i < numberTests; i++)
  14.             {
  15.                 int requiredQuantity;
  16.                 int bottleQuantity;
  17.                 int sinkQuantity;
  18.  
  19.                 bool hasSuccess = false;
  20.  
  21.                 int[] commands = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  22.              
  23.  
  24.                 bottleQuantity = commands[0];
  25.                 sinkQuantity = commands[1];
  26.                 requiredQuantity = commands[2];
  27.                 Stack<int> sink = new Stack<int>(sinkQuantity);
  28.                 Stack<int> bottle = new Stack<int>(bottleQuantity);
  29.                 int leftInTheBottle = 0;
  30.                 int count = 0;
  31.  
  32.                 int bottleCount = 0;
  33.                 int sinkCount = 0;
  34.  
  35.                
  36.              
  37.  
  38.                 bool a = false;
  39.                 if (requiredQuantity > bottleQuantity)
  40.  
  41.                 {
  42.  
  43.                    
  44.  
  45.                     while (requiredQuantity>bottleQuantity)
  46.                     {
  47.                         bottleCount++;
  48.                         requiredQuantity -= bottleQuantity;
  49.                     }
  50.  
  51.                    
  52.                     a = true;
  53.                 }
  54.  
  55.                 while (true)
  56.                 {
  57.                     if (bottle.Count ==requiredQuantity )
  58.                     {
  59.                         hasSuccess = true;
  60.                         break;
  61.                        
  62.                     }
  63.                     else
  64.                     {
  65.                        
  66.                             for (int m = 0; m < bottle.Count; m++)
  67.                             {
  68.                                 sink.Push(bottle.Pop());
  69.                             m--;
  70.                             }
  71.                        
  72.                     }
  73.  
  74.                     bool hasFill = false;
  75.                         for (int j = 0; j < bottleQuantity; j++)
  76.                         {
  77.                         if (bottle.Count == bottleQuantity) { break; }
  78.                         else
  79.                         {
  80.                             bottle.Push(1);
  81.                             hasFill = true;
  82.                         }
  83.                         }
  84.                     if (hasFill)
  85.                     {
  86.                         bottleCount++;
  87.                     }
  88.                        
  89.                    
  90.                     for (int m = 0; m < bottle.Count; m++)
  91.                     {
  92.                         if (sink.Count == sinkQuantity)
  93.                         {
  94.                             leftInTheBottle = bottle.Count;
  95.                             sink.Clear();
  96.                             sinkCount++;
  97.                             break;
  98.                         }
  99.                         else
  100.                         {
  101.  
  102.                             sink.Push(bottle.Pop());
  103.                             m--;
  104.                         }
  105.                     }
  106.  
  107.  
  108.                     if (count == 1000000)
  109.                     {
  110.                         break;
  111.                     }
  112.                    
  113.                     count++;
  114.                    
  115.  
  116.                 }
  117.  
  118.  
  119.                 if (hasSuccess)
  120.                 {
  121.                     if (a)
  122.                     {
  123.                         Console.WriteLine($"{bottleCount} {sinkCount}");
  124.  
  125.                     }
  126.                     else
  127.                     {
  128.                         Console.WriteLine($"{bottleCount} {sinkCount}");
  129.  
  130.                     }
  131.  
  132.                    
  133.                 }
  134.                 else
  135.                 {
  136.                     Console.WriteLine("IMPOSSIBLE");
  137.                 }
  138.             }
  139.  
  140.         }
  141.     }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment