1 model (4) day2

Source: Internet
Author: User

Question 1:

What is the result of the binary number N mod m? The length of N (the number of digits of the binary number) <= 200 000; the length of M (the number of digits of the binary number) <= 20.

 

Problem solving process:

1. My algorithm is a direct and high-precision simulation, but the data has a leading 0, and all four vertices with a leading 0 are wa .. The programming complexity of high-precision division is indeed a bit.

2. the scalar algorithm is much simpler. Considering that m length is not large, it is calculated directly and then modulo n, because N can be split into 2 ^ X1 + 2 ^ X2 ..... 2 ^ XK, scanning from left to right, adding the number of current bits to 2 each time, modulo m .. I did not really think of it when I used the same theorem.

 

Question 2:

The path from A to B requires the minimum product of Edge Weight. Edge Weight of each edge C <= 10 ^ 9

 

Problem solving process:

1. the bare Shortest Path is short-circuited. if the product is too large, it may take a log to convert the product .. I encountered this type of question for the first time and accumulated experience. Spfa is always wrong. Today I re-reviewed it again and finally I can write it right ..

 

Question 3:

The relationship between m people and friends was given. At first, a person had an infectious disease, and all his friends came back to visit him. Then, the next day, he got ill, all the friends are ill. The next day after the illness, they will be immune and will not be ill again .. Anyone who is ill will visit him .. After how many days, everyone will be ill. Or it will never end.

 

Problem solving process:

1. at the beginning, the answer was "guaranteed to be less than 2*10 ^ 9". After I wrote a few pieces of data, I thought it would be nice to perform a wide search. A person could not be infected twice, no solution is more impossible, and then dare not write. After that, I wrote out the wide search. The result was originally the depth of the wide search tree. I output the number of nodes.

2. The AC algorithm is really wide search, which is not very good description. You can simulate it to know that a person cannot be infected twice.

1 model (4) day2

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.