21609_HospitalAgain

2022-5-16 18:19| 发布者: Hocassian| 查看: 22| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505684436900-Problem List-采集的数据-后羿采集器.html

Pro.ID

21609

Title

Hospital Again

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21609

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Theme hospital? Yes, it’s theme hospital again!

    The hospital has n doctors and divides into four groups. Every group would be changed during the patients’ medical care. Each doctor has his own number and the doctors can belong to all the groups.

    At the first day when the hospital open, the doctors would divide into four groups according to their own number. So if the total number of four groups are gug2,g3,g4, and then the doctors will divide as this:

    Group 1: 1, 2, ..., g1

    Group 2: g1+1, g1+2, ..., g1+g2

    Group 3: g1+g2+1, g1+g2+2, ..., g1+g2+g3

    Group 4: g1+g2+g3+1, g1+g2+g3+2, ..., g1+g2+g3+g4

    And then, the first patient will choose doctor 1, and when the doctor 1 finished, he will go to the last position of group 2. The second patient will choose doctor g1+1, and when finished, the doctor will go the last position of group 3... The k-th patient will choose the first doctor of group k%4, and when finished, the doctor will go the last position of group (k+1)%4.

    The hospital will have m patients in one day. And before another day begins, the doctors will also divide into the four groups according to the last day. They will just combine the four groups, and then divide into four groups into g1, g2, g3 and g4. So if the end of the day is:

    Group 1: d1, d2, ..., dk1                  Group 2: dk1+1, dk1+2, ..., dk2

    Group 3: dk2+1, dk2+2 , ..., dk3         Group 4: dk3+1, dk3+2, ..., dk4

    Then they combine into

    d1, d2, ..., dk1, dk1+1, dk1+2, ..., dk2, dk2+1, dk2+2, ..., dk3, dk3+1, dk3+2, ..., dk4

    And at last, they divide into four groups again:

    Group 1: d1, d2, ..., dg1

    Group 2: dg1+1, dg1+2, ..., dg1+g2

    Group 3: dg1+g2+1, dg1+g2+2, ..., dg1+g2+g3

    Group 4: dg1+g2+g3+1, dg1+g2+g3+2, ..., dg1+g2+g3+g4

    After that, the patients will choose the doctors just the same as the first day and so on.

    After a few days,at the beginning of the day, the doctors' arrange will just same as the first day!

    Can you tell me when it comes?

    输入

    This problem contains multiply test cases. In each test cases, there are five integers g1, g2, g3, g4, p ( 1 ≤ g1, g2, g3, g4 ≤ 20, p ≤ 10000 ) per line, that stands for the number of group 1, group 2, group 3, group 4 and the total patients in one day.

    The input will terminated by g1=g2=g3=g4=p=0 and the number of test cases will not exceed 12000.

    输出

    Description

    Theme hospital? Yes, it’s theme hospital again!

    The hospital has n doctors and divides into four groups. Every group would be changed during the patients’ medical care. Each doctor has his own number and the doctors can belong to all the groups.

    At the first day when the hospital open, the doctors would divide into four groups according to their own number. So if the total number of four groups are gug2,g3,g4, and then the doctors will divide as this:

    Group 1: 1, 2, ..., g1

    Group 2: g1+1, g1+2, ..., g1+g2

    Group 3: g1+g2+1, g1+g2+2, ..., g1+g2+g3

    Group 4: g1+g2+g3+1, g1+g2+g3+2, ..., g1+g2+g3+g4

    And then, the first patient will choose doctor 1, and when the doctor 1 finished, he will go to the last position of group 2. The second patient will choose doctor g1+1, and when finished, the doctor will go the last position of group 3... The k-th patient will choose the first doctor of group k%4, and when finished, the doctor will go the last position of group (k+1)%4.

    The hospital will have m patients in one day. And before another day begins, the doctors will also divide into the four groups according to the last day. They will just combine the four groups, and then divide into four groups into g1, g2, g3 and g4. So if the end of the day is:

    Group 1: d1, d2, ..., dk1                  Group 2: dk1+1, dk1+2, ..., dk2

    Group 3: dk2+1, dk2+2 , ..., dk3         Group 4: dk3+1, dk3+2, ..., dk4

    Then they combine into

    d1, d2, ..., dk1, dk1+1, dk1+2, ..., dk2, dk2+1, dk2+2, ..., dk3, dk3+1, dk3+2, ..., dk4

    And at last, they divide into four groups again:

    Group 1: d1, d2, ..., dg1

    Group 2: dg1+1, dg1+2, ..., dg1+g2

    Group 3: dg1+g2+1, dg1+g2+2, ..., dg1+g2+g3

    Group 4: dg1+g2+g3+1, dg1+g2+g3+2, ..., dg1+g2+g3+g4

    After that, the patients will choose the doctors just the same as the first day and so on.

    After a few days,at the beginning of the day, the doctors' arrange will just same as the first day!

    Can you tell me when it comes?

    Input

    This problem contains multiply test cases. In each test cases, there are five integers g1, g2, g3, g4, p ( 1 ≤ g1, g2, g3, g4 ≤ 20, p ≤ 10000 ) per line, that stands for the number of group 1, group 2, group 3, group 4 and the total patients in one day.

    The input will terminated by g1=g2=g3=g4=p=0 and the number of test cases will not exceed 12000.

    Output

    Print one line of an integer what is the meaning of at this day, the doctors will same as the first day. The answer will not exceed 231.

    Sample Input

    2 1 1 1 6
    0 0 0 0 0

    Sample Output

    3

    Hint

    At first day, no patients come would be    g1: 1  2     g2:3     g3:4     g4:5

    1 patients: g1:2       g2:3  1    g3:4       g4:5

    2 patients: g1:2       g2:1        g3:4  3   g4:5

    3 patients: g1:2       g2:1        g3:3       g4:5  4

    4 patients: g1:2  5   g2:1        g3:3       g4:4

    5 patients: g1:5       g2:1  2    g3:3       g4:4

    6 patients: g1:5       g2:2        g3:3  1   g4:4

    So after one day: the four groups will be   g1:5  2     g2:3     g3:1     g4:4

    After 2 day: g1:4  2     g2:3     g3:5     g4:1

    After 3 day: g1:1  2     g2:3     g3:4     g4:5

    Source

    样例输入

    2 1 1 1 6
    0 0 0 0 0

    样例输出

    3

    提示

    At first day, no patients come would be    g1: 1  2     g2:3     g3:4     g4:5

    1 patients: g1:2       g2:3  1    g3:4       g4:5

    2 patients: g1:2       g2:1        g3:4  3   g4:5

    3 patients: g1:2       g2:1        g3:3       g4:5  4

    4 patients: g1:2  5   g2:1        g3:3       g4:4

    5 patients: g1:5       g2:1  2    g3:3       g4:4

    6 patients: g1:5       g2:2        g3:3  1   g4:4

    So after one day: the four groups will be   g1:5  2     g2:3     g3:1     g4:4

    After 2 day: g1:4  2     g2:3     g3:5     g4:1

    After 3 day: g1:1  2     g2:3     g3:4     g4:5


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部