Several randomization questions

Source: Internet
Author: User

The random algorithm is good, and chaos creates a miracle.

 

Pro: give an n * m mesh with a color or barrier on each grid. The smallest connected block without barrier contains at least k colors.

N, m <= 100 Color <= N * M k <= 5

 

SOL: When the color is small, for example, color = K, it is a bare stanna tree. Then, each time we randomly divide all the colors into k boxes, one box is dyed into the same color, and then follow the above method to take the minimum value. It is feasible to Solve the Problem each time. The optimal solution is that the color of the random to the final answer is in different boxes, probably K! /(K ^ K ).

 

Pro: For a undirected graph, ask the number of solutions to delete two edges to make the graph not connected. N, m <= 10 ^ 5

 

SOL: first build a spanning tree, random a weight for all non-tree sides, and then overwrite the tree edge to the XOR value, finally, edge pairs with the same weight or where the right value is 0 (cut edge) are feasible.

However, this is a deterministic practice.

 

Pro: A comparison method for multiple sets: to see where the smallest number of elements that appear differently is small. For a sequence, ask the K size of multiple sets formed by consecutive subsequences (the same number is also multiple times ). (N <= 10 ^ 5, k <= N * (n + 1)/2)

 

SOL: If a set is given, it is better to calculate the number of <= It. Note that the Left endpoint is fixed, and the set size increases with the right endpoint. Use heap for maintenance.

Then, a random interval is randomly located in all feasible intervals as a two-boundary, and then a feasible right endpoint range is calculated. No. It is expected to be O (nlog ^ 2n.

 

Pro: Find the largest group.

 

SOL: Random a vertex sequence, and then add it if greedy. Bitset can be used for optimization.

This year, WF has a question, but that question has a deterministic algorithm, but it can still be done!

 

Cf also has a lot of questions that use randomization, and I feel pretty good.

444b dzy loves FFT

442e Gena and second distance

#213 div1d GHD

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.