k-nearest neighbor algorithm for machine learning in real-world combat

1. KNN's Movie Classification For a new movie, how do you tell if it's a love movie or an action movie? You can tell by the number of kisses or fights. Compare this movie with many already tagged movies, calculate the Euclidean distance between them, sort by distance, and find the shortest k (three below)And then see how many of these k are lo ...

Posted by TurtleDove on Sat, 09 Oct 2021 11:20:47 -0700

⭐Introduction to Algorithms⭐Heap 03 - LeetCode 373.Find and Minimum K Pair Number

1. Title 1. Title Description Given two arrays of integers nums1 and nums2 in ascending order, and an integer k k k. Define a pair of values ( u , ...

Posted by shiggins on Sat, 09 Oct 2021 10:02:47 -0700

Standard Template Library algorithm (all functions)

Catalog Adjacent_find All_of (returns true if all iterator intervals meet criteria, false otherwise) Any_of (returns true if one of the iterator intervals meets the criteria, false otherwise) Binary_search (binary search, find return true, otherwise return false) Copy (copy an interval to the target iterator location) Copy_backward (copy ...

Posted by cpace1983 on Sat, 09 Oct 2021 09:47:06 -0700

Minimum refueling times

Title: the car starts from the starting point to the destination, which is located at the target mile east of the starting position. There are gas stations along the way. Each station[i] represents a gas station. It is located at station[i][0] miles east of the starting position, and there are station[i][1] liters of gasoline. Suppose that ...

Posted by jokerofsouls on Sat, 09 Oct 2021 02:42:46 -0700

PAT Basic Level 1089 werewolf killing - simple version problem solving ideas and AC code v0.96

1. Topic description and online test location 1.1 N people play werewolf killing, and each person explains the identity of others according to the number sequence from 1 to N. it is known that there are two werewolves in n people, two people lied when describing the identity of others, and only one werewolf lied. Judge who is a werewolf ac ...

Posted by champrock on Sat, 09 Oct 2021 00:36:22 -0700

Algorithm learning notes - merge sort

Merge sort Merging is an algorithm based on divide and conquer, which is to split an array into small arrays in half, sort them in turn, and finally merge these sorted arrays. (divide and Conquer: big problems are divided into small problems and solved one by one) Stepwise analysis Suppose we have an array of {5, 8, 1, 0, 2, 9, 7, 4}. We ne ...

Posted by harinath on Fri, 08 Oct 2021 20:27:38 -0700

Classic example of introduction to algorithm competition 6-13

UVa1103 Ancient Messages Identify hieroglyphs. Because there is only one black connected pixel block in a hieroglyphic, and the hieroglyphics do not cover each other, the hieroglyphics can be divided according to the black connected pixel block; Because the number of white connected pixel blocks in each hieroglyphic is different, the hierogl ...

Posted by tskweb on Thu, 07 Oct 2021 17:24:24 -0700

Dynamic programming idea

0 Idea of dynamic programming: when analyzing the choice of the first i objects, under the condition that all possible values of constraints are taken, first find the optimal solution of each sub problem of constraint value, so that when analyzing the addition of the i+1 object, you can directly call the solution of one or more sub problems th ...

Posted by wata on Thu, 07 Oct 2021 14:40:22 -0700

leetcode brush record day019:384 and 198

384. Medium difficulty: Method 1: Violence: time complexity O(n^2) space complexity O(n) Topic meaning: the topic requires us to implement a constructor and two methods of the Solution class 1. Solution(int[] nums) initializes the object with an integer array nums // Title passed in array nums public Solution(int[] nums) { // Array and n ...

Posted by DJTim666 on Thu, 07 Oct 2021 13:41:41 -0700

The end of the holiday - 8 kinds of optimization of algorithms such as quick sorting rekindle your desire to learn

Bubble sorting and its optimization Basic idea of bubble sorting 1. Access each element of the array from scratch and exchange between adjacent elements 2. Exchange elements in pairs. Change the small one to the front and the large one to the back. 3. After all elements are exchanged, one exchange is completed, and the largest element will ...

Posted by james_4k2 on Thu, 07 Oct 2021 11:34:15 -0700