Poj-1006:biorhythms Detailed 2: Overlay

Source: Internet
Author: User

> Analysis

>> because days can be less than P, E, I, so first let p,e,i equals the beginning of the respective first cycle>> Three-step overlay, starting from d+1 according to test instructions days1. Calculate the point of the first days% = = P (This step can be calculated once)2. Starting with the results from the previous step, find the point of the first days% = = e, and increase each3. Starting with the result of the previous step, find the point of the first days% = = I, increase each time > Note>> calculate days must be greater than D, so the loop can start directly from D+1>> If End of loop is used, note days <= 21252 + 365 > attached Code
1 /* ------------------------------2 * Overlay and take out surplus3  * ----------------------------*/4#include"stdio.h"5 6 #defineCycle_p 237 #defineCycle_e 288 #defineCycle_i 339 Ten intMainvoid) One { A     intp =0, E =0, i =0, d =0 ; -     intCount =0 ; -     intDays =0 ; the  -      while(1) -     { -scanf"%d %d%d%d", &p, &e, &i, &d); +         if(-1==d) -              Break ; +  Ap = p%cycle_p; atE = e%cycle_e; -i = i%cycle_i; -          -Days = d +1; -      -         if(Days <=p) inDays =p; -         Else     toDays + = cycle_p-(days-p)%cycle_p; +  -          while(days% cycle_e! =e) theDays + =cycle_p; *  $          while(days% cycle_i! =i)Panax NotoginsengDays + = Cycle_p *cycle_e;  -  theprintf"Case %d:the Next triple peak occurs in%d days.\r\n", +++count, Days-d); A     } the  +     return 0 ; -}

Poj-1006:biorhythms Detailed 2: Overlay

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.