PTA --- greedy algorithm

7-1 packing problem import java.util.Scanner; public class Program1 { public static void main(String[] args) { int N; Scanner in = new Scanner(System.in); N = in.nextInt(); int []things = new int[N]; //Up to N boxes int []box = new int[N]; //Record the maximum number of boxes ...

Posted by webbnino on Wed, 20 Oct 2021 20:33:54 -0700

Personal algorithm Beginner - greedy algorithm

Example: The best time to buy and sell stocks II Given an array prices, where   prices[i] is the price of a given stock on day I. Design an algorithm to calculate the maximum profit you can make. You can complete as many transactions as possible (buying and selling a stock multiple times). Note: you cannot participate in multiple t ...

Posted by WhiteHawk on Wed, 20 Oct 2021 11:15:10 -0700

Algorithm learning: 1-1 greedy algorithm

The so-called greedy algorithm is to ensure that each operation is a local optimal solution, so that the final result is a global optimal solution. Exercise 1:455. Distribute cookies The key to using greedy algorithm is to find greedy strategy, that is, each operation is a local optimal solution. As can be seen from the question, to satisf ...

Posted by Pastulio on Mon, 27 Sep 2021 06:37:57 -0700

C + + language learning summary and experience

        About the language part of C + + (Information Science Orsay one pass), I myself summarized some knowledge.         Because it is too basic, I won't talk about the introduction and use of the first part of the source code.         I'll start with the second chapter, sequent ...

Posted by Onloac on Tue, 21 Sep 2021 14:18:01 -0700

Codeforces Round #743 (Div. 2) (A~C)

Competition link: Click here to transfer Link to official solution: Click here to transfer 1573A Countdown topic link: Click here to transfer Meaning: There is a sequence, you have to change it all into 0. You can perform the following two operations to exchange elements in two positions, which is the last element minus one. Find the minim ...

Posted by fr0mat on Tue, 21 Sep 2021 03:38:55 -0700

Codeforces Round #741 (Div. 2) (A~D2)

Competition link: Click here to transfer Link to official solution: Click here to transfer 1562A The Miracle and the Sleeper topic link: Click here to transfer Meaning: Given a range [ l , r ] ...

Posted by Daddy on Mon, 20 Sep 2021 05:48:00 -0700

Leetcode: 68. Align text left and right

subject Source: LeetCode Link: https://leetcode-cn.com/problems/text-justification Given an array of words and a length maxWidth, rearrange the words into text with exactly maxWidth characters per line and aligned left and right ends. You should use "greedy algorithm" to place a given word; That is, put as many words in each line as ...

Posted by ozzythaman on Fri, 10 Sep 2021 01:02:00 -0700