> 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