<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ~~~ # Delta-wave Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6931????Accepted Submission(s): 2674 ~~~ Problem Description A triangle field is numbered with successive integers in the way shown on the picture below.? ![](https://box.kancloud.cn/2016-02-29_56d3edfe0ed4c.jpg) The traveller needs to go from the cell with number M to the cell with number N. The traveller is able to enter the cell through cell edges only, he can not travel from cell to cell through vertices. The number of edges the traveller passes makes the length of the traveller's route.? Write the program to determine the length of the shortest route connecting cells with numbers N and M.? Input Input contains two integer numbers M and N in the range from 1 to 1000000000 separated with space(s). Output Output should contain the length of the shortest route. Sample Input ~~~ 6 12 ~~~ ? Sample Output ~~~ 3 ~~~ **求最近的路徑的大小,本質上這個題中每一個塊可以表示為三個坐標的形式,那就是水平方向的第幾層,左側的左側第幾列,右側看右側第幾列,比如說:1這個元素在水平第1層,左側第1列,右側第1列; 6這個元素是水平第3層,左側第2層,右側第1層,那么1到6的計算就是這三個坐標的差的絕對值之和:2+1+0 = 3 ,也就是說1到6需要3步。** 剩下的自然是怎么求出來各個方向上的位置咯:水平方向是level = sqrt(num - 1) + 1,左側的坐標可以表示為:left = ( level*level - num)/ 2 +1,? 右側的坐標可以表示為:right = (num- (level-1)*(level-1) - 1)/ 2 + 1 那么剩下的就是將兩個點的三個坐標的值對應求差然后去絕對值再求和就可以了 ~~~ import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()) { int num1 = scanner.nextInt(); int num2 = scanner.nextInt(); int level1 = (int)Math.sqrt(num1 - 1) + 1; int left4num1 = (level1*level1 - num1)/2 + 1; int right4num1 = (num1 - (level1 - 1) * (level1 - 1) - 1)/2 + 1; int level2 = (int)Math.sqrt(num2 - 1) + 1; int left4num2 = (level2*level2 - num2)/2 + 1; int right4num2 = (num2 - (level2 - 1) * (level2 - 1) - 1)/2 + 1; System.out.println(Math.abs(level1 - level2) + Math.abs(left4num1 - left4num2) + Math.abs(right4num1 - right4num2)); } } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看