Skip to content

Instantly share code, notes, and snippets.

@WindAzure
Last active September 16, 2018 16:27
Show Gist options
  • Save WindAzure/d084a9f2df251039377eeaf81da586d1 to your computer and use it in GitHub Desktop.
Save WindAzure/d084a9f2df251039377eeaf81da586d1 to your computer and use it in GitHub Desktop.
UVa 756
#include <stdio.h>
#include <iostream>
#define COMMON_MULTIPLE 21252 + 365
#define MAX_LEN_CYCLE COMMON_MULTIPLE + 1
using namespace std;
int cycleTable[MAX_LEN_CYCLE] = { 0 };
void MarkUp(int biorhythmsDayOfBeginningYear, int period)
{
biorhythmsDayOfBeginningYear %= period;
for (auto day = biorhythmsDayOfBeginningYear; day <= COMMON_MULTIPLE; day += period)
{
cycleTable[day] ++;
}
}
int main()
{
auto physical = 0, emotional = 0, intellectual = 0, dayAlreadyPassed = 0, T = 1;
while (~scanf("%d%d%d%d", &physical, &emotional, &intellectual, &dayAlreadyPassed))
{
if (physical == -1 && emotional == -1 && intellectual == -1 && dayAlreadyPassed == -1) break;
fill(cycleTable, cycleTable + MAX_LEN_CYCLE, 0);
MarkUp(physical, 23);
MarkUp(emotional, 28);
intellectual %= 33;
for (auto day = intellectual; day <= COMMON_MULTIPLE; day += 33)
{
if (day <= dayAlreadyPassed) continue;
if (cycleTable[day] == 2)
{
printf("Case %d: the next triple peak occurs in %d days.\n", T++, day - dayAlreadyPassed);
break;
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment