<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 查找具有最大漢明距離的旋轉 > 原文: [https://www.geeksforgeeks.org/find-a-rotation-with-maximum-hamming-distance/](https://www.geeksforgeeks.org/find-a-rotation-with-maximum-hamming-distance/) 給定 n 個元素的數組,請創建一個新數組,該數組是給定數組的旋轉,并且兩個數組之間的漢明距離最大。 [兩個長度相等的數組或字符串之間的漢明距離](https://en.wikipedia.org/wiki/Hamming_distance)是相應字符(元素)不同的位置數。 **注意**:對于給定的輸入,可以有多個輸出。 例子: ``` Input : 1 4 1 Output : 2 Explanation: Maximum hamming distance = 2. We get this hamming distance with 4 1 1 or 1 1 4 input : N = 4 2 4 8 0 output : 4 Explanation: Maximum hamming distance = 4 We get this hamming distance with 4 8 0 2. All the places can be occupied by another digit. Other solutions can be 8 0 2 4, 4 0 2 8 etc. ``` 創建另一個數組,該數組的大小是原始數組的兩倍,以使此新數組(復制數組)的元素只是原始數組的元素,并按相同順序重復兩次。 例如,如果原始數組為`1 4 1`,則副本數組為`1 4 1 1 4 1`。 現在,遍歷副本數組并查找每次移位(或旋轉)的漢明距離。 因此,我們檢查`4 1 1, 1 1 4, 1 4 1`,選擇漢明距離最大的輸出。 下面是上述方法的實現: ## C++ ```cpp // C++ program to Find another array // such that the hamming distance? // from the original array is maximum #include <bits/stdc++.h> using namespace std; // Return the maximum hamming distance of a rotation int maxHamming(int arr[], int n) { ????// arr[] to brr[] two times so that ????// we can traverse through all rotations. ????int brr[2 *n + 1]; ????for (int i = 0; i < n; i++) ????????brr[i] = arr[i]; ????for (int i = 0; i < n; i++)? ????????brr[n+i] = arr[i]; ????// We know hamming distance with 0 rotation ????// would be 0\. ????int maxHam = 0;???? ????// We try other rotations one by one and compute ????// Hamming distance of every rotation ????for (int i = 1; i < n; i++) ????{ ????????int currHam = 0; ????????for (int j = i, k=0; j < (i + n); j++,k++)? ????????????if (brr[j] != arr[k]) ?????????????????currHam++; ????????// We can never get more than n.? ????????if (currHam == n) ????????????return n; ????????maxHam = max(maxHam, currHam); ????} ????return maxHam; } // driver program int main()? { ????int arr[] = {2, 4, 6, 8};???? ????int n = sizeof(arr)/sizeof(arr[0]); ????cout << maxHamming(arr, n);???? ????return 0; } ```
                  <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>

                              哎呀哎呀视频在线观看