<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<!-- DOMjudge version 3.3.2 -->
<title>Source: s1395</title>
<link rel="shortcut icon" href="../images/favicon.png" type="image/png" />
<link rel="stylesheet" href="../style.css" type="text/css" />
<link rel="stylesheet" href="style_jury.css" type="text/css" />
<script type="text/javascript" src="../js/sorttable.js"></script>
<script type="text/javascript" src="../js/domjudge.js"></script>
</head>
<body>

<h2>Source code for submission s1395</h2>

<p><a href="#diff">Go to diff to previous submission</a></p>

<div class="tabber"><div class="tabbertab"><h2 class="filename"><a name="source0"></a>grasshop.cpp</h2> 

<pre class="cpp" style="font-family:monospace;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #339900;">#include &lt;cstdio&gt;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666;">//~ #include &lt;math.h&gt;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #0000ff;">int</span> pole<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">102</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">102</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #0000ff;">int</span> velX,velY,startX,startY,cilX,cilY<span style="color: #008080;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #0000ff;">int</span> max <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> a, <span style="color: #0000ff;">int</span> b<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span> <span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span>a<span style="color: #000080;">&gt;</span>b<span style="color: #008000;">&#41;</span><span style="color: #008080;">?</span>a<span style="color: #008080;">:</span>b<span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #0000ff;">int</span> <span style="color: #0000dd;">abs</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> a<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span> <span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span>a<span style="color: #000080;">&lt;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">?</span> <span style="color: #000040;">-</span>a <span style="color: #008080;">:</span> a<span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #0000ff;">int</span> vzdalenost<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> X,<span style="color: #0000ff;">int</span> Y<span style="color: #008000;">&#41;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000;">&#123;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	X<span style="color: #000080;">=</span><span style="color: #0000dd;">abs</span><span style="color: #008000;">&#40;</span>cilX<span style="color: #000040;">-</span>X<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	Y<span style="color: #000080;">=</span><span style="color: #0000dd;">abs</span><span style="color: #008000;">&#40;</span>cilY<span style="color: #000040;">-</span>Y<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	<span style="color: #0000ff;">return</span> max<span style="color: #008000;">&#40;</span>X,Y<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000;">&#125;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #0000ff;">int</span> best<span style="color: #008080;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #0000ff;">void</span> rekurze<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> X,<span style="color: #0000ff;">int</span> Y, <span style="color: #0000ff;">int</span> N<span style="color: #008000;">&#41;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000;">&#123;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	<span style="color: #666666;">//~ printf (&quot;---- %d %d\n&quot;,X,Y);</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>X<span style="color: #000080;">&lt;</span><span style="color: #0000dd;">1</span><span style="color: #000040;">||</span>Y<span style="color: #000080;">&lt;</span><span style="color: #0000dd;">1</span><span style="color: #000040;">||</span>X<span style="color: #000080;">&gt;</span>velX<span style="color: #000040;">||</span>Y<span style="color: #000080;">&gt;</span>velY<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span><span style="color: #008080;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>X <span style="color: #000080;">==</span> cilX <span style="color: #000040;">&amp;&amp;</span> Y <span style="color: #000080;">==</span> cilY<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>best<span style="color: #000080;">==</span><span style="color: #000040;">-</span><span style="color: #0000dd;">1</span> <span style="color: #000040;">||</span> best <span style="color: #000080;">&gt;</span> N<span style="color: #008000;">&#41;</span> best <span style="color: #000080;">=</span> N<span style="color: #008080;">;</span><span style="color: #008000;">&#125;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	<span style="color: #0000ff;">else</span> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">		<span style="color: #008000;">&#123;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">			rekurze<span style="color: #008000;">&#40;</span>X<span style="color: #000040;">+</span><span style="color: #0000dd;">2</span>,Y<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span>,N<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">			rekurze<span style="color: #008000;">&#40;</span>X<span style="color: #000040;">+</span><span style="color: #0000dd;">2</span>,Y<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span>,N<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">			rekurze<span style="color: #008000;">&#40;</span>X<span style="color: #000040;">-</span><span style="color: #0000dd;">2</span>,Y<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span>,N<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">			rekurze<span style="color: #008000;">&#40;</span>X<span style="color: #000040;">-</span><span style="color: #0000dd;">2</span>,Y<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span>,N<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">		<span style="color: #008000;">&#125;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000;">&#125;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000;">&#123;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	<span style="color: #666666;">//~ int velX,velY,startX,startY,cilX,cilY;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	<span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">scanf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%d%d%d%d%d%d&quot;</span>,<span style="color: #000040;">&amp;</span>velX,<span style="color: #000040;">&amp;</span>velY,<span style="color: #000040;">&amp;</span>startX,<span style="color: #000040;">&amp;</span>startY,<span style="color: #000040;">&amp;</span>cilX,<span style="color: #000040;">&amp;</span>cilY<span style="color: #008000;">&#41;</span><span style="color: #000080;">==</span><span style="color: #0000dd;">6</span><span style="color: #008000;">&#41;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	<span style="color: #008000;">&#123;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">		<span style="color: #0000ff;">int</span> best <span style="color: #000080;">=</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">		rekurze<span style="color: #008000;">&#40;</span>startX,startY,<span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>best<span style="color: #000080;">==</span><span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;impossible<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">		<span style="color: #0000ff;">else</span> <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>,best<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">	<span style="color: #008000;">&#125;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #008000;">&#125;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li></ol></pre></div></div><h2><a name="diff"></a>Diff to submission <a href="1373">s1373</a></h2>
<div class="tabber"><div class="tabbertab"><h2 class="filename"><a name="diff"></a>grasshop.cpp</h2>

<pre class="output_text"><span class='diff-del'>--- c4.s1373.cteam039.grasshop.cpp.0.grasshop.cpp</span>
<span class='diff-add'>+++ c4.s1395.cteam039.grasshop.cpp.0.grasshop.cpp</span>
@@ -16,35 +16,18 @@
 }
 
<span class='diff-del'>-void rekurze(int X,int Y,int N)</span>
<span class='diff-add'>+int best;</span>
<span class='diff-add'>+</span>
<span class='diff-add'>+void rekurze(int X,int Y, int N)</span>
 {
         //~ printf (&quot;---- %d %d\n&quot;,X,Y);
         if (X&lt;1||Y&lt;1||X&gt;velX||Y&gt;velY) return;
<span class='diff-del'>-        if (pole[X][Y]==-1 || pole[X][Y]&gt;N) pole[X][Y]=N;</span>
<span class='diff-del'>-        else return;</span>
<span class='diff-del'>-        if (vzdalenost(X,Y)&gt;5)</span>
<span class='diff-del'>-        {</span>
<span class='diff-del'>-                if (cilX&gt;X)</span>
<span class='diff-del'>-                {</span>
<span class='diff-del'>-                        rekurze(X+2,Y-1,N+1);</span>
<span class='diff-del'>-                        rekurze(X+2,Y+1,N+1);</span>
<span class='diff-del'>-                }</span>
<span class='diff-del'>-                else</span>
<span class='diff-del'>-                {</span>
<span class='diff-del'>-                        rekurze(X-2,Y-1,N+1);</span>
<span class='diff-del'>-                        rekurze(X-2,Y+1,N+1);</span>
<span class='diff-del'>-                }</span>
<span class='diff-del'>-                if (cilY&gt;Y)</span>
<span class='diff-del'>-                {</span>
<span class='diff-del'>-                        rekurze(X-1,Y+2,N+1);</span>
<span class='diff-del'>-                        rekurze(X+1,Y+2,N+1);</span>
<span class='diff-del'>-                }</span>
<span class='diff-del'>-                else</span>
<span class='diff-add'>+        </span>
<span class='diff-add'>+        </span>
<span class='diff-add'>+        </span>
<span class='diff-add'>+        </span>
<span class='diff-add'>+        </span>
<span class='diff-add'>+        if (X == cilX &amp;&amp; Y == cilY) {if (best==-1 || best &gt; N) best = N;}</span>
<span class='diff-add'>+        else </span>
                 {
<span class='diff-del'>-                        rekurze(X-1,Y-2,N+1);</span>
<span class='diff-del'>-                        rekurze(X+1,Y-2,N+1);</span>
<span class='diff-del'>-                }</span>
<span class='diff-del'>-        }</span>
<span class='diff-del'>-        else</span>
<span class='diff-del'>-        {</span>
                         rekurze(X+2,Y-1,N+1);
                         rekurze(X+2,Y+1,N+1);
@@ -53,10 +36,7 @@
                         rekurze(X-2,Y+1,N+1);
                         
<span class='diff-del'>-                        rekurze(X+1,Y+2,N+1);</span>
<span class='diff-del'>-                        rekurze(X-1,Y+2,N+1);</span>
<span class='diff-del'>-                        </span>
<span class='diff-del'>-                        rekurze(X+1,Y-2,N+1);</span>
<span class='diff-del'>-                        rekurze(X-1,Y-2,N+1);</span>
<span class='diff-del'>-        }</span>
<span class='diff-add'>+                </span>
<span class='diff-add'>+                }</span>
<span class='diff-add'>+        </span>
 }
 
@@ -67,11 +47,9 @@
         while (scanf(&quot;%d%d%d%d%d%d&quot;,&amp;velX,&amp;velY,&amp;startX,&amp;startY,&amp;cilX,&amp;cilY)==6)
         {
<span class='diff-del'>-                for (int i=1;i&lt;=velX;i++)</span>
<span class='diff-del'>-                        for (int j=1;j&lt;=velY;j++)</span>
<span class='diff-del'>-                                pole[i][j]=-1;</span>
<span class='diff-del'>-                </span>
<span class='diff-add'>+                int best = -1;</span>
<span class='diff-add'>+                                </span>
                 rekurze(startX,startY,0);
<span class='diff-del'>-                if (pole[cilX][cilY]==-1) printf(&quot;impossible\n&quot;);</span>
<span class='diff-del'>-                else printf(&quot;%d\n&quot;,pole[cilX][cilY]);</span>
<span class='diff-add'>+                if (best==-1) printf(&quot;impossible\n&quot;);</span>
<span class='diff-add'>+                else printf(&quot;%d\n&quot;,best);</span>
         }
         
</pre>

</div></div>
</body>
</html>
