Poj 1006 Problem Solving report

Source: Internet
Author: User

 

1003,1004, 1005 too much water, not recordedCode. 1006 is also very simple. It is just a problem of undefined equations, because the problem is not clearly described, or because my mind is dizzy because I am not sleeping at noon, after reading the question several times, I did not understand what the meaning of the data is. I understood it only after reading the Chinese translation several times.

# Include <iostream>

Using namespace STD;

Int main ()

{

Int P, E, I, D;

Int start, Day;

Int COUNT = 1;

While (true)

{

Cin> P> E> I> D;

If (P =-1 & E =-1 & I =-1 & D =-1)

Break;

P = P % 23, E = E % 28, I = I % 33;

If (d <p)

Start = 0;

Else

Start = (D-P)/23 + 1; // Add 1 here, after the given date (excluding the given date)

For (int ix = start; ++ IX)

{

Day = P + 23 * IX;

If (day <E | day <I)

Continue;

If (day-D> 21252)

{

Cout <"case" <count ++ <": The next Triple peak occurs in" <21252 <"days." <Endl;

Break;

}

Else if (day-e) % 28 = 0 & (day-I) % 33 = 0)

{

Cout <"case" <count ++ <": The next Triple peak occurs in" <day-D <"days." <Endl;

Break;

}

}

}

Return 0;

}

The conclusion of this question is that if the Chinese Remainder Theorem is applied, it will be calculated in O (1) time, which is very powerful. For details, see

Http://blog.csdn.net/ChinaCzy/archive/2010/04/29/5544250.aspx

 

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.