<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9762&amp;view=findpost&amp;p=93943</guid>
        <pubDate>Tue, 26 Nov 2002 08:50:04 +0000</pubDate>
        <title>Подкиньте алгоритмик... plz</title>
        <link>https://forum.sources.ru/index.php?showtopic=9762&amp;view=findpost&amp;p=93943</link>
        <description><![CDATA[S.Yu.Gubanov: Понятно, что &quot;The friend printed first on the line is considered to be the winner of the game&quot; - это чушь. Входной информации недостаточно, чтобы определить победителей. А также &quot;It is guaranteed that for every test case there will be at least one possible scheduling of the games&quot; тоже не очевидно, что есть всего один возможный граф...<br>  <br>Следующая прога для заданных начальных условий (2,4,1,5) выполняется на P4 1800Mhz не более чем за 0.016 сек (часто за 0.000 сек)<br><br><br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>type TVertex      = Array[0..100] of integer; //Игроки<br>     TConnection  = record v1, v2: integer; end;<br>     TConnections = Array[0..10000] of TConnection; //Партии<br><br>var  Vertex: TVertex;<br>     HighVertex: integer;<br>     Connections: TConnections;<br>     HighConnections: integer;<br>     t,i,j: integer;<br>     suc: boolean;<br>     dt: cardinal;<br>begin<br>  Randomize;<br>  suc := False; //не удалось найти решение<br>  ProgressBar1.Max := 1000; //максимальное количество попыток<br>  ProgressBar1.Position := 0;<br>  dt := GetTickCount; // засекаем время потраченное на поиск решения<br>  //работаем до тех пор пока не найдется решение или пока не надоест искать<br>  while (not suc) and (ProgressBar1.Position &lt; ProgressBar1.Max) do<br>  begin<br>    ProgressBar1.Position := ProgressBar1.Position + 1;<br>    // Вводим начальные данные<br>    Vertex[0] := 2; // первый игрок играл 2 раза<br>    Vertex[1] := 4; // второй игрок играл 4 раза<br>    Vertex[2] := 1; // третий игрок играл 1 раз<br>    Vertex[3] := 5; // четвертый игрок играл 5 раз<br>    HighVertex := 3;<br>    //сейчас будем искать кто с кем чем занимался...<br>    HighConnections := -1;<br>    //сделаем, например, 100000 попыток, <br>    //макс число вариантов = 10000, так что 100000 попыток хватит на все<br>    for t := 1 to 100000 do <br>      begin<br>        //Случайно выбираем пару игроков<br>        i := Random(HighVertex + 1);<br>        j := Random(HighVertex + 1);<br>        if (i &lt;&gt; j) and (Vertex[i] &gt; 0) and (Vertex[j] &gt; 0) then<br>          begin<br>           inc(HighConnections);<br>           Connections[HighConnections].v1 := i;<br>           Connections[HighConnections].v2 := j;<br>           //Эти игроки свою партию отыграли<br>           dec(Vertex[i]);<br>           dec(Vertex[j]);<br>          end;<br>      end;<br>    //Проверяем замкнулся ли граф<br>    suc := True;<br>    for i:=0 to HighVertex do if Vertex[i] &gt; 0 then suc := False;<br>  end;<br>  dt := GetTickCount - dt;<br>  if not suc then<br>    ShowMessage('Не удалось отыскать решение, попробуйте увеличить количество попыток.')<br>  else<br>    begin<br>      Memo1.Clear;<br>      Memo1.Lines.Add('Количество партий = '+IntToStr(HighConnections + 1));<br>      for i:=0 to HighConnections do Memo1.Lines.Add(IntToStr(Connections[i].v1+1)<br>        +' '+IntToStr(Connections[i].v2+1));<br>      Memo1.Lines.Add('Время поиска '+FloatToStr(dt*0.001)+' сек');<br>    end;<br>end;<br><br><br>P.S.<br>Забыл что в результирующем списке надо упорядочить так чтоб в последующей строке был победитель из предыдущей строки... Хм... возможно это и даст всего один возможный вариант...<br>]]></description>
        <author>S.Yu.Gubanov</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9762&amp;view=findpost&amp;p=93942</guid>
        <pubDate>Mon, 25 Nov 2002 16:05:48 +0000</pubDate>
        <title>Подкиньте алгоритмик... plz</title>
        <link>https://forum.sources.ru/index.php?showtopic=9762&amp;view=findpost&amp;p=93942</link>
        <description><![CDATA[R_Ally: Как я понял, это задача из какой-то олимпиады, причем явно не нашей<br>(судя по языку). Если есть линк на &quot;сайт-исходник&quot; - кинь на форум -<br>там могут быть дополнительные условия.<br> Например, непонятно, выбывает ли проигравший из турнира или нет,<br>на какой машине нужны эти 0.5 сек. и т.п.<br><br>]]></description>
        <author>R_Ally</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9762&amp;view=findpost&amp;p=93941</guid>
        <pubDate>Mon, 25 Nov 2002 10:41:10 +0000</pubDate>
        <title>Подкиньте алгоритмик... plz</title>
        <link>https://forum.sources.ru/index.php?showtopic=9762&amp;view=findpost&amp;p=93941</link>
        <description><![CDATA[PropellerMan: &nbsp;Я тут внимательно посмотрел на пример выходного файла и мне кое-что пришло на ум: может быть стоит выбрать игрока, у которого больше всего сыгранных партий и составить пары с ним и другими игроками. Затем, если в какой-то момент после составления очередной пары у него стало меньше игр чем у кого либо, то проделать тоже самое с тем, у кого на данный момент больше всего игр. И т.д. до нулей.<br>P.S. Походу по входным данным можно составить уйму возможных пар (без учета последовательности игр).]]></description>
        <author>PropellerMan</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9762&amp;view=findpost&amp;p=93940</guid>
        <pubDate>Mon, 25 Nov 2002 08:07:52 +0000</pubDate>
        <title>Подкиньте алгоритмик... plz</title>
        <link>https://forum.sources.ru/index.php?showtopic=9762&amp;view=findpost&amp;p=93940</link>
        <description><![CDATA[Slava: Есть N друзей. 2&lt;=N&lt;=100. Сначала берётся один из них и играет с любым другим в шахматы. Победитель вновь выбирает себе любого из друзей и играет с ним и т. д. <br> <br>Входной файл: <br>Первая строка - N <br>Вторая - a[1]-a[n], где a[i] - кол-во сыграных партий i'ым другом 1&lt;=a[i]&lt;=10000 <br> <br>Выходной файл: <br>Первая строка: Кол-во сыгранных партий всего. (M) <br>Следущие М строк в формате: победитель проигравший. <br> <br> <br>Вот оригинальный текст, если вдруг задачу я перевёл криво: <br> <br>Time Limit: 0.5 sec <br> <br>N friends gathered in order to play chess, according to the following rules. In the first game, two of the N friends will play. In the second game, the winner of the first game will play against another friend (maybe even the same friend who lost the first game). In the third game, the winner of the second game will play against someone else and so on.. No game will end as a draw (tie). Given the number of games each of the N friends played, find a schedule for the games, so that the above rules are obbeyed. &nbsp;<br> <br> <br>Input <br> <br>The first line contains the number of friends N (2&lt;=N&lt;=100). The second line contains N integers, separated by blanks, representing the number of games each friend played. The first number represents the number of games played by the first friend, the second number represents the number of games played by the second friend and so on.. &nbsp;<br> <br> <br>Output <br> <br>The first line should contain the number of games played by all the friends (it will be an integer between 1 and 10 000, for every test case). Let's suppose this number is G. Then, G lines follow, each of them containing two integers, describing the games. The first line contains the numbers of the two friends who played the first game. The friend printed first is considered to be the winner. Each of the next G-1 lines contain the integers a and b, where a&lt;&gt;b and a or b is the winner of the previous game. The friend printed first on the line is considered to be the winner of the game. &nbsp;<br>It is guaranteed that for every test case there will be at least one possible scheduling of the games. &nbsp;<br> <br> <br>Sample Input <br> <br>4 <br>2 4 1 5 <br> <br> <br>Sample Output <br> <br>6 <br>4 3 <br>4 1 <br>2 4 <br>2 1 <br>4 2 <br>2 4 <br> <br>Люди, ещё кое-что. Я не хочу вас затруднять лишними проблемами, поэтому буду очень рад просто алгоритму, а не исходнику задачи. Хочется решить именно эту задачу, т.к. из всех, которых нам дали - она самая сложная, хотя могу взять и другую. <br> <br>Единственное что сам раскопал: Нечётное кол-во партий у i-ого друга означает, что он хоть одну партию да проиграл, ну и само собой общее кол-во партий=сумме(a[i])/2, где 1&lt;=i&lt;=n. <br> <br>Вроде всё. Заранее благодарен. <br>]]></description>
        <author>Slava</author>
        <category>Алгоритмы</category>
      </item>
	
      </channel>
      </rss>
	