Binary Search Algorithm

background

Today, Xiao Zheng, Xiao Ming and Xiao Hong are playing a guessing game, with Xiao Hong playing the banker. The rules of the game are that each contestant has three chances. If the contestant has not guessed the number after using up three chances, they will treat the dealer to a lollipop. If they guess correctly, the dealer will treat them to a candy bar. Eat a lollipop.

Now the game starts, please ask Xiaohong to write down a number on a sticky note. Xiao Hong wrote 97 on the post-it note in anticipation.

Xiao Ming: 50, right?

Xiaohong: No, it’s too small

Xiao Zheng: 75, is that okay?

Xiaohong: Haha, wrong, too small

Xiao Ming: 87, right?

Xiaohong: You are wrong again, it is too small

Xiao Zheng: 93, right?

Xiaohong: Almost, it’s too small

Xiao Ming: Is it 96?

Xiaohong: What a pity. You have no chance. Please eat a lollipop.

Xiao Zheng replied thoughtfully: 97

Xiaohong: Wow, you are great. Let’s go eat lollipops.

From the example above, we can extract a model. Given a set of ordered arrays, compare the target value with the value near the middle of the range each time. If it is too large, give the middle value to the left range and then find it from the middle value of the new range. If it is too small, give the middle value to The right range is searched from the middle value of the new range. If it is found, we return the index corresponding to its array subscript. If it is not found, we return -1. A search method like this is called "binary search".

Implement a binary search algorithm

There is a question about binary search. We will use this as an example to implement a binary search.

Question description

Given an n-element sorted (ascending) integer array nums and a target value, write a function to search nums and return the subscript if the target value exists, otherwise return -1.

Example 1:

Input: nums = [-1,0,3,5,9,12], = 9 Output: 4 Explanation: 9 appears in nums with subscript 4

Example 2:

Input: nums = [-1,0,3,5,9,12], = 2 Output: -1 Explanation: 2 does not exist in nums so -1 is returned

Example 3

Input: nums=[2, 5], =2

Output: 0,

Explanation: 2 appears in nums and has subscript 0

hint:

You can assume that all elements in nums are unique. n will be between [1, 10000]. Each element of nums will be between [-9999, 9999].

The tips here are very helpful for reviewing the question. The first sentence tells you to rest assured that these data are not repeated. You can rest assured to write in the simplest way. The second sentence tells you that only 10,000 numbers are enough to survive. , the amount of data is pretty good. The third sentence tells you that you don’t have to worry about the range of the integer type overflowing, and this is a signed integer type. So the tips are still helpful, although they may not be reflected in the code.

Ideas

Let’s first analyze what binary search does? It's nothing more than taking the middle one within a range and comparing the size with the target element. If it doesn't exactly equal the target element, I will continue to select one of the two segments and continue to chop it until the last element is left. So obviously we need a while loop to help us do such a thing. The second thing we have to think about is, what are the conditions for this while loop to be established? We can't create an endless cycle. When the left flag is less than or equal to the right flag, we continue to loop. It may be easy for everyone to understand here, so what is the situation? Let’s take an example from Example 3. When I want to find the number 5, left=mid=0, right=1 for the first time. At this time, we find that it is too small. Then if the equal sign is not taken, We just exited, so we added the equal sign here. When left=right=1 for the second time, we just found it. Then we think about the third thing, which half should I take? At this time, you need to determine the size of the middle one and the target one. If it is too big, I will subtract 1 from the middle one and assign it to right. If it is too small, then I will add 1 to the middle one and assign it to left. , and then recalculate the middle one and compare again. Okay, let's code one code together.

Code

/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var search = function(nums, target) {
  var left = 0;
  var right = nums.length - 1;
  var mid = left + Math.floor((right - left) / 2);
  while(left  nums[mid]) {
      left = mid + 1;
    } else if (target < nums[mid]) {
      right = mid - 1;
    } else if (target === nums[mid]) {
      return mid;
    }
    mid = left + Math.floor((right - left) / 2);
  }
  return -1;
};

Question: What is the time complexity of binary search?

Let’s talk about the answer first, O(logn). The rough process is, n(1/2)^k = 1. If we work backwards, k = log2n, the time complexity reflected on the computer is logn.

What scenarios are binary search applicable to?

The interview is for brushing people off (because it is easy to make mistakes), the amount of data is medium, and the data does not overflow the range. The most important thing is to perform a binary search on a set of sorted numbers.

Take our first example above. The ordinary search takes 97 times, but the binary search idea is used 6 times. Isn't this very delicious?

references

704.Binary search():

Emuchat Simulator Top Cheat (emu Cheat 2010)

The emulator top cheat is a very practical game simulation modifier. Users who like to play games can use this tool to easily modify the game data in the emulator. Moreover, this tool is a free version and can be used, installed and The operations are very simple and easy to understand, even a novice can easily get started. Friends in need can come to the Green Resource Network to download it!

Modifier introduction

Contains: Emu Cheat 2010, 2009, Chf Ansi format conversion tool, usage tutorial

basic knowledge

Run the game first, then open EC, then click on the emulator selection

mt manager modification_ec modifier_How to modify Calabash Man with the modifier

Select the emulator in the drop-down list, if set in the options

After selecting a supported emulator, a list of game cheat codes will automatically pop up.

Check the items you want to modify and click Activate Cheat Code.

Go back to the game and you can see the effect

mt manager modification_ec modifier_How to modify Calabash Man with the modifier

exact search

It is also convenient to search for precise numerical values. Take Dragon Quest 3 as an example. This time we want to modify money.

The current money in the game is 50G, so what we want to search for is 50

The search results are out, but there are a lot of addresses. Let’s continue searching.

ec modifier_How to modify Calabash Man with the modifier_mt manager modification

Just buy some props first and let the money value change.

There are 42G of money left. Let’s search again and see.

This time it’s good. There are only two addresses left. Let’s lock it and take a look. Since what we want to modify is money, it doesn’t matter if the value is larger.

Switched back to the game interface, it was successful, and the money became 65535.

ec modifier_How to modify Calabash Man with the modifier_mt manager modification

In fact, this method can not only be used to modify money, but also can be used to modify abilities and so on.

fuzzy search

What we want to modify this time is the blood tank, but how to find it if there is no specific value like this?

This requires fuzzy search. Take Yuehua Swordsman 2 as an example. Start after selecting the character.

mt manager modification_How to modify Calabash Man to use the modifier_ec modifier

Open EC, because we don’t know what the blood tank value is at this time, so we need to find it first?

The search results are not satisfactory. There are too many addresses. Let’s continue.

Let the opponent hit you first. After the blood tank is reduced, pause and search again.

After repeating the search several times, there are only a few addresses left. It would be too laborious to continue searching.

Just find an address and lock it. There is a trick here. Try to lock the value the same as the game.

Switched back to the game interface, got hit a few times by the opponent, and the health gauge did not decrease. We succeeded. This is the address we are looking for.

Extracting passwords:

Mame32 Simulator Chinese Version

The emulator provides you with an emulator that allows you to play arcade machines in arcades. With this simulator you can relive the classic arcade games of the past. In the software, you can set individual settings for each game to give you the most classic experience. Welcome to download!

Introduction to the PC version of the simulator:

The simulator is a large-scale video game emulator suitable for the win32 platform. In addition to designing this software for educational purposes, the author also hopes to use it to preserve some classic large-scale video games that were popular in the 1970s and 1980s.

Instructions:

1. Place the downloaded game zip folder in the "roms" folder of the emulator (do not unzip it) and start running the program .exe

2. Press "f5" to refresh the search game list (refresh when a new game is added, the refresh time is much longer than that of earlier versions, please wait patiently)

3. After refreshing and searching, click "Own Game" in the left column

4. Press "tab" during the game to set the normal button configuration and single game button configuration.

5. After being online, for the Chinese version, the game list will change to English. Click the word "中" on the toolbar to restore the Chinese game list.

6. The "snap" folder stores game preview images

Software features:

1. Supports additional functions such as cheat, high score, flyer, etc.

2. The plus simulator supports the ips function and can automatically load and modify the code. There is a game search function. The interface window can be adjusted.

3. Graphical interface, the plus simulator supports Linux and multiple languages.

4. Support the display of historical documents from multiple countries on the same screen.

365 Game Box App

365 Game Box app is a game mall, where you can find the most complete variety of games on the Internet, with complete categories and clear classifications. As long as you want to play, there is nothing you can’t find, and it can meet almost all your needs, without downloading, that is Click to play, it is very convenient, saves mobile phone space, and does not lag; I recommend everyone to download and experience it!

Software introduction

"365 Game Box" is a mobile software that allows you to find more different games more easily. In 365 Game Box, you will be able to search for more different game resources, and your search will be more efficient. Simple, lots of exciting content can be found easily.

Software features

1. Various games can be found, making your search and acquisition easier and more convenient;

2. A great game tool that allows you to query more different games;

3. Game push is faster and it is easier to obtain more different game resources.

Software advantages

1. Various game resources can be searched and found, making it easier and more convenient to obtain;

2. It brings together more popular resources, and various games are waiting for you to find;

3. There are more game rewards waiting for you to collect, which can be obtained with one click.

Software Highlights

1. Interesting and fun games can be found, searched at any time, and obtained quickly;

2. A simpler gameplay makes it easier to get your game, go play the game;

3. A variety of games also allow you to compete online, making the gameplay more relaxed and interesting.

Software description

1. Get rewards for safe interaction. A large number of modes are waiting for you to challenge, and you will gain a lot.

2. Log in quickly with one click, continue daily tasks, and enjoy exciting battles.

3. You can play together online, with various exciting experiences, and thousands of people can play online for free.

UltraEdit-32 V15.00.0

It is an editor that can meet all your editing needs. It is a powerful text editor that can edit text, hexadecimal, and ASCII codes. It can replace Notepad. It has built-in English word checking, C++ and VB command highlighting, and can edit multiple files at the same time, even if you open a lot of files. Large files are not slow either. The software comes with HTML tag color display, search and replace, and unlimited restore functions. Generally, people like to use it to modify EXE or DLL files.

Software features

The text editor has built-in English word checking, C++ and VB command highlighting, and can edit multiple files at the same time, and the speed will not be slow even when opening large files. The software comes with HTML tag color display, search and replace, and unlimited restore functions. Generally, people like to use it to modify EXE or DLL files. It is a powerful text editor that can edit text, hexadecimal, and ASCII codes. It can replace Notepad. It has built-in English word checking, C++ and VB command highlighting, and can edit multiple files at the same time, even if you open many files. There will be no lag on large files.

1. Configurable syntax highlighting, support for code folding, and 64-bit file processing on 32-bit platforms.

2. Disk-based text editing and support for large file processing exceeding 4GB, even multi-megabyte files occupy very little memory;

3. Support multi-line find and replace dialog boxes in all search operations (find, replace, find in file, replace in file);

4. Spell checker with 100,000 words, pre-configured for C/C++, VB, HTML, Java and Perl;

5. Built-in FTP client, supports logging in and saving multiple accounts, and supports SSH/window;

6. Provide a predefined or user-created editing "environment" that can remember the status of all dockable windows, toolbars, etc.;

7. Integrated scripting language to automate tasks, configurable keyboard mapping, column/block mode editing, named templates;

8. The hex editor can edit any binary file and display binary and ASCII views;

9. HTML toolbar, pre-configured for commonly used HTML functions; file encryption/decryption; multi-byte and integrated IME.

10. Web Search Toolbar: Highlight the text and click the Web Search Toolbar button to start searching for the highlighted words from within the editor;

Tip: There is an option to set the homepage during the installation process, please pay attention to your selection.

Change log

1. Configurable syntax highlighting, support for code folding, and 64-bit file processing on 32-bit platforms.

2. Disk-based text editing and support for large file processing exceeding 4GB, even multi-megabyte files occupy very little memory;

3. Support multi-line find and replace dialog boxes in all search operations (find, replace, find in file, replace in file);

4. Spell checker with 100,000 words, pre-configured for C/C++, VB, HTML, Java and Perl;

Nebula Game Modifier Download V9.0 PC Version

Nebula Game Modifier is a tool for modifying the internal data of the game. This software is powerful and does not require any operating skills. You can learn how to operate it at a glance. It helps you pass quickly or get invincible equipment in advance by modifying game data. Currently, the data it can modify include game gold coins, game levels, weapons and equipment, unlimited health, increased attack power, and many other powerful functions. Nebula Game Modifier PC version is a safe and non-toxic software. It is recommended to modify data when using stand-alone games, so that account bans are less likely to occur.

Nebula game modifier software functions

1. The game modifier is a universal and universal game modifier that can modify any data in online games and local games.

2. Modify and lock multiple data (such as HP value, money, experience, etc.) in the game memory at the same time.

3. Can modify all values ​​in the game such as life, level, game speed, experience, money, etc., and lock the content.

4. Find bugs in online game data brushing, game acceleration and other functions. It is a good tool for modifying game data.

5. Focus on achieving accurate positioning of game data queries and accelerating query efficiency.

6. The data of online games has certain analysis functions, making it easy to find bugs in online game data brushing, game acceleration and other functions, and advanced users can also expand the functions according to their own level.

Nebula game modifier software features

1. A free, full-featured universal game modifier with small size and simple interface.

2. Easy to operate, powerful functions, main functions, convenient for you to quickly pass the level.

3. At the same time, it has certain analysis functions for online game data, making it easy to find bugs in online game data brushing, game acceleration and other functions.

4. You can expand the functions according to your own level.

5. Nebula, written in assembly language, combines powerful functions with faster game data query speed, allowing you to play the game easily.

6. Accurate positioning of data query and accelerated query efficiency.

Nebula game modifier installation steps

1. Download Nebula Game Modifier from this site, unzip it, double-click to run it, and follow the prompts to install it.

Notice:

Nebula Game Modifier comes with bundled software. During installation, you will be prompted whether to install Baidu Toolbar. Please select "Yes", otherwise the modifier cannot be installed.

Then the following page will pop up. Select "Cancel Installation" and the Baidu Toolbar will not be bundled and installed.

How to use the PC version of Nebula Game Modifier

1. After unzipping the file, run [.exe] to open the modifier. You can select the name of the game (the name of the EXE file) in the process list on the left.

2. After double-clicking, the current process below will appear. Now you can enter a value (for example, you want to modify the character's HP value at this time, which is now 100) to search.

3. After the search is completed, some data will appear in the memory list on the right. At this time, there is usually a lot of data, and it is difficult to determine the specific memory address to be modified.

4. At this time, you can return to the game to change the HP value, and then use the hotkey ALT+Q (or ALT+TAB) to call out the nebula.

5. Enter this value again to search (you cannot click Refresh All at this time). The final result will likely have two or more memory addresses. When the addresses are the same, please select the bottom address in the memory list to modify.

6. Click Refresh All to refresh the process list. You can do this when the required information does not appear in your process list.

7. If you need to lock a certain value, you can double-click a row in the memory list to send the data of this row to the place where the locked value is loaded below, and then click lock.

8. If you want to re-search or refresh the process, please click Refresh All. If you need to modify and lock more values ​​at the same time, please click New Task, and a window similar to the main interface will appear, and the operation is exactly the same.

Kindergarten Game Lesson Plan "Eagle Catches Chicken"

Find:

Selection of activity themes This folk game is mainly played in the form of role-playing. If the class is large, it can be played in groups. In view of the characteristics of small class children, they are more interested in role-playing, suitable for some imitation games, and can experience happy emotions in the process of dodging and running, so I chose this game to let the children know how to cooperate in the game.

Activity goals:

Eagle catching chicks game_Eagle catching chicks game_Eagle catching chicks game eagle lesson plan

1. Exercise children’s dodge ability and the development of large muscle groups

2. Exercise children’s ability to respond and cooperate with each other

Eagle catching chicks game_Eagle catching chicks game eagle lesson plan_Eagle catching chicks game

Activity preparation: eagle, mother chicken, chick headdress

Activity process: beginning part

Eagle catching chicks game eagle lesson plan_Eagle catching chicks Chicken Game_Eagle Catching Chicken Game

1. All children perform warm-up activities: nodding, stretching arms, bending, kicking, jumping and other movements.

2. Ask one child to be the "mother chicken", the teacher to be the "eagle", and the rest to be the "chicks".

Eagle catching chicks game_Eagle catching chicks game_Eagle catching chicks game eagle lesson plan

3. The mother chicken spread out with the chicks, and said while imitating: "Chicken chirp chirp,… where are the little bugs?"

4. The "Eagle" flew over, and the "Mother Chicken" opened her arms: "Children, quickly hide under mother's wings." The chicks lined up in a vertical line, holding the clothes of the children in front of them with both hands, and chanting children's songs together. : "The eagle flies in the sky, and the chicken jumps on the ground. The eagle catches the chicken, but it just can't catch it."

Catching Chicken Game Eagle Lesson Plan_Eagle Catching Chicken Game_Eagle Catching Chicken Game

5. The "eagle" captures the "chicken" in the team. "Mother Chicken" opens her arms to protect the "chick", and the "chick" moves left and right with the "mother" and dodges dexterously to prevent the "eagle" from catching it.

6. The caught "chicken" leaves the venue.

7. When the "Eagle" catches a quarter or a third of the "Chickens", switch roles and start the game again.

Find: