CodeForces 471C MUH and House of Cards

Source: Internet
Author: User

CodeForces 471C MUH and House of Cards

After reading the Hint graph of the question, you can see that the number of cards required for each layer is 2 * n + (n-1, then there is a general idea: brute-force enumeration, but there is no way to enumerate it. This formula only represents one layer. It is impossible to enumerate each layer, the formula can be reduced to 3 * n-1, so that 1 is a multiple of 3, and 1 is different for each layer. If there is an I layer, it is actually worse than I, so it is easy to think of. Assuming there are a total of x cards, it is actually enumerating I, how many I makes (x + I) % 3 = 0, this is simple, but there is a limit, because you need to know the number of cards required to build the I layer, and the Buen has more than x cards, I need to draw more pictures here, and later I found that building layer I requires at least (3 * I + 1) * I/2 cards, so that it is easy to determine the enumerated range, and the answer is not big, so it's okay to enumerate the answer directly.

 

Question link: click here

 

I thought it was a little tricky. If the answer was too big, I would just look at what others did and find a better way. In fact, the difference between each layer is a multiple of 3, which is equivalent, subtraction of 2 on each layer is a multiple of 3, which is not an enumeration (x + I) % 3 = 0. You can enumerate down (x-3 * (j-1) -2 * j) % 3 = 0; therefore, you do not need to consider the upper limit, which reduces the time used to find the formula.

 

 

Ll n; void init () {} bool input () {while (cin> n) {return false;} return true;} void cal () {ll ans = 0ll; for (ll k = 1; k ++) {if (n <(3 * k + 1) * k/2) break; if (n + k) % 3 = 0) ans ++;} cout <

 

Related Article

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.