Shuffle cards in reverse order - breadth first search BFS

1. Problem description This question comes from question 42 in the interesting question of programmer's algorithm. Suppose there are 2n playing cards. Each time we draw n cards from them (not scattered, but a continuous stack of cards) and place them on the top of the stack. Then repeat this operation until the order of cards is opposite to t ...

Posted by derwert on Thu, 30 Dec 2021 01:58:58 +0100

Topological sorting of hand-in-hand Teaching

Topological sorting of hand-in-hand Teaching In graph theory, * * Topological Sorting Is a linear sequence of all vertices of a directed acyclic graph (DAG) * *. And the sequence must meet the following two conditions: Each vertex appears only once.If there is A path from vertex A to vertex B, vertex A appears in front of vertex B in the ...

Posted by BLaZuRE on Thu, 30 Dec 2021 00:30:49 +0100

Force deduction method 1705 - maximum number of apples to eat

Original title link: Force buckle Description: There is a special apple tree, which can grow several apples every day for n days. On day I, apples[i] will grow on the tree. These apples will rot and become inedible after days[i] (that is, on day i + days[i]). It is also possible that new apples will not grow on the tree for a few days. At th ...

Posted by Atari on Wed, 29 Dec 2021 21:50:10 +0100

Search algorithm (linear, bisection, interpolation, Fibonacci)

1. Linear search algorithm Idea: judge whether the quantity contains this name (sequential search) requirement. If it is found, it will prompt to find it and give the subscript value. Code implementation: public class SeqSearch { public static void main(String[] args) { int arr[]={1,3,5,23,45,54,65,71,143}; System.out.pri ...

Posted by StathisG on Wed, 29 Dec 2021 21:02:03 +0100

[data structure] stack / queue / sorting algorithm

What is a linear table for? (sequential list and linked list) linear storage data Stack concept: implemented with linear table - last in first out - LIFO last in first out Stack (also known as stack): a container that can store data elements for access and deletion Single end operation: it is only allowed to add (push) and output (pop) data ...

Posted by kender on Wed, 29 Dec 2021 20:12:09 +0100

OJ 1576 user password login continuous failure locking problem

#include<iostream> #include<vector> #include<string> #include<list> #include<utility> #include<stdlib.h> using namespace std; bool isfind_ch(vector<pair<char, int>> vec, char ch) { //Is there a pair with ch as the key in char tmpt; tmpt = toupper(ch); //All uppercase storage for (int i = (v ...

Posted by msinternet on Wed, 29 Dec 2021 19:30:45 +0100

Calculator function implementation (stack)

Calculator function implementation (stack) input 15*5+(5+1)/6-7 output 69 Problem solving ideas Because priority should be considered in actual calculation, we need to establish a function. Here, I name it get (char x). X is the formula we enter, I set the priority of "(") as' 0 'at the lowest, followed by' + 'and' - 'as 1,' * ' ...

Posted by deolsabh on Wed, 29 Dec 2021 18:52:23 +0100

[dynamic programming] 01 knapsack and its optimization

Title Description There are N items and a backpack with a capacity of V. The space consumed by putting the i-th item is Ci, and the value obtained is Wi. Solve which items can be loaded into the backpack to maximize the total value without exceeding the capacity. Input format Two positive integers in line 1 represent N and V respecti ...

Posted by cpharry on Wed, 29 Dec 2021 13:27:25 +0100

Implementation of sword finger offer go version Chapter 3: high quality code

Main purpose of this chapter It mainly focuses on high-quality code, completeness, standardization and robustness.The writing of test cases is usually done hastily in order to complete the unit test coverage. After studying this chapter, we can find that our previous test cases are very poor in practicability. There are only normal cases, and ...

Posted by DeathStar on Wed, 29 Dec 2021 13:01:57 +0100

Generation from knowledge map to text -- twelve

2021SC@SDUSC We continue to analyze the remaining key code of the evaluate() function. final_scores = self.score(ref, hypo) Final here_ Scores saves the final evaluation score according to the three evaluation methods mentioned in the previous blog. Here, the score function is called, which is the class function of Evaluate. The code is as ...

Posted by carichod on Wed, 29 Dec 2021 12:56:57 +0100