Hdoj-1370-biorhythms "Chinese remainder theorem"

Source: Internet
Author: User

BiorhythmsTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): Accepted submission (s): 861


Problem Descriptionsome people believe that there be three cycles in a person's life that start the day he or she's born . These three cycles is the physical, emotional, and intellectual cycles, and they have periods of lengths, D, and Ays, respectively. There is one peak in each period of a cycle. At the peak of a cycle, a person performs at the corresponding field (physical, emotional or mental). For example, if it is the mental curve, thought processes would be sharper and concentration would be easier.

Since the three cycles has different periods, the peaks of the three cycles generally occur at different times. We would like-to-determine when a triple peak occurs (the peaks of all three cycles occur in the "Same day") for any person. For each cycle, you'll be given the number of days from the beginning of the current year at which one of its peaks (no T necessarily the first) occurs. You'll also be given a date expressed as the number of days from the beginning of the current year. You task was to determine the number of days from the given date to the next triple peak. The given date is not counted. For example, if the given date is ten and the next triple peak occurs on day, the answer was 2, not 3. If a triple peak occurs on the given date, you should give the number of days to the next occurrence of a triple peak.


This problem contains multiple test cases!

The first line of a multiple input was an integer N and then a blank line followed by N input blocks. Each input block was in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.

Inputyou'll be given a number of cases. The input for each case consists of a line of four integers p, E, I, and D. The values P, E, and I are is the number of days from the beginning of the which the physical, emotional, and Intellectual cycles peak, respectively. The value D is the given date and could be smaller than any of P, E, or I. All values is non-negative and at most 365, and your may assume that a triple peak would occur within 21252 days of the GIV En date. The end of input is indicated by a line in which p = e = i = d =-1.

Outputfor each test case, print the case number followed by a message indicating the number of days to the next triple pea K, in the form:

Case 1:the Next triple peak occurs in 1234 days.

Use the plural form "days" even if the answer is 1.

Sample Input
10 0 0 00 0 0 1005 20 34 3254 5 6 7283 102 23 320203 301 203 40-1-1-1-1

Sample Output
Case 1:the Next triple peak occurs in 21252 days. Case 2:the Next triple peak occurs in 21152 days. Case 3:the Next triple peak occurs in 19575 days. Case 4:the Next triple peak occurs in 16994 days. Case 5:the Next triple peak occurs in 8910 days. Case 6:the Next triple peak occurs in 10789 days.

Sourceeast Central North America 1999; Pacific Northwest 1999
Recommendeddy | We have carefully selected several similar problems for you:1788 1452 1695 1211 1852
#include <stdio.h>/*int f (int a,int b,int c) {int T=a*b;while (t%c!=1) {t+=a*b;} return t;} */int Main () {int t,ncas=0;scanf ("%d", &t), while (t) {ncas++;int a,b,c,d;scanf ("%d%d%d%d", &a,&b,&c, &D); if (a==-1&&b==-1&&c==-1&&d==-1) {T--, ncas=0;continue;} int t= (5544*a+14421*b+1288*c-d+21252)%21252;printf ("Case%d:the next triple peak occurs in%d days.\n", ncas,t?t:21252);} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdoj-1370-biorhythms "Chinese remainder theorem"

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.