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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 每次成功搜索后通過將元素加倍來重復搜索 > 原文: [https://www.geeksforgeeks.org/repeatedly-search-element-doubling-every-successful-search/](https://www.geeksforgeeks.org/repeatedly-search-element-doubling-every-successful-search/) 給定一個數組“ a []”和整數“ b”。 查找 b 是否存在于 a []中。 如果存在,則將 b 的值加倍并再次搜索。 我們重復這些步驟,直到找不到 b。 最后,我們返回 b 的值。 例子: ``` Input : a[] = {1, 2, 3} b = 1 Output :4 Initially we start with b = 1\. Since it is present in array, it becomes 2. Now 2 is also present in array b becomes 4 . Since 4 is not present, we return 4. Input : a[] = {1 3 5 2 12} b = 3 Output :6 ``` 問題來源:在 Yatra.com 在線測試中提出 1)對輸入數組進行排序。 2)繼續進行二分搜索并加倍,直到不存在該元素。 以下代碼在 STL 中使用 [binary_search()](https://www.geeksforgeeks.org/binary-search-algorithms-the-c-standard-template-library-stl/) ## C++ ```cpp // C++ program to repeatedly search an element by // doubling it after every successful search #include <bits/stdc++.h> using namespace std; int findElement(int a[], int n, int b) { ????// Sort the given array so that binary search ????// can be applied on it ????sort(a, a + n); ????int max = a[n - 1]; // Maximum array element ????while (b < max) { ????????// search for the element b present or ????????// not in array ????????if (binary_search(a, a + n, b)) ????????????b *= 2; ????????else ????????????return b; ????} ????return b; } // Driver code int main() { ????int a[] = { 1, 2, 3 }; ????int n = sizeof(a) / sizeof(a[0]); ????int b = 1; ????cout << findElement(a, n, b); ????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>

                              哎呀哎呀视频在线观看