And Now For Something Completely Different!
Time limit1sMemory limit128 MB
The program scans a chore record for split points where both halves favor the opposite child from the total and prints each match with rounded percentages.
- Level
Medium4 of 10
- Topics
- Prefix sum, Simulation, Implementation
- Solved
- No attempts yet
Problem
Bart and Lisa Simpson get plenty of chores, and they do not always do them well. So their father started keeping score, giving credit only when a chore was done right. After a month he showed them what he had written down.
The first month, in the order the chores were handed out:
Bart did 3 of his 4 chores right, so 75.00%. Lisa did 2 of her 3 right, so 66.67%.
The second month looked like this:
Bart did 1 of 2, so 50.00%. Lisa did 3 of 7, so 42.86%.
Their father then put the two months together to argue that Bart does the most chores:
Lisa looked at the tables and said "No no no, that's not right, I've done more." Bart pointed at the numbers and said "Numbers don't lie." Lisa said "But look, I've done 5 chores and you've only done 4. You just look good because you always run away before somebody asks you to do something." Bart laughed and ran away.
Now Lisa needs a program that shows how unfair this scoring is. It reads one long record of chores and finds every place where cutting the record into a before part and an after part makes both parts point the opposite way from the whole record. To keep things fair, she counts a cut only when Bart and Lisa both have chores assigned on both sides of it.
Stated exactly: a record holds chores, numbered 1 to in the order they were handed out. Over the whole record let be the number of chores Bart did right and the number Lisa did right. When the two differ, the larger one is the conclusion of the whole record. Cutting after chore , where , splits the record into chores 1 to and chores to . The cut counts only when both children have at least one chore in each part. Inside a part, a child's percentage is the number of chores that child did right in the part, divided by the number of chores assigned to that child in the part, times 100. The cut reverses the conclusion of the whole record when the child named by that conclusion has the lower percentage in both parts.
Input
The input holds several records. The first line of a record holds the number of chores (). Each of the next lines holds Bart or Lisa, one space, and 0 or 1. The name is the child the chore was assigned to, and the number is 1 when the chore was done right and 0 when it was not. Every record has at least one chore for Bart and at least one for Lisa. The last line of the input holds 0 in place of a record.
Output
For each record, print the record number and how many chores each child did right on the first line:
Case <case number>: Bart did <CB> and Lisa did <CL>
If and are equal there is no conclusion to oppose, so print this on the next line:
Bart and Lisa accomplished same number of chores
If they differ, look at every cut that counts. If none of them reverses the conclusion of the whole record, print this on the next line:
Simpson's paradox not detected
If at least one does, print this on the next line:
Trend measured in 2 parts is reversed
and then one line per reversing cut, in increasing order of chore number:
After chore <chore number>: <BBefore>% <LBefore>% <BAfter>% <LAfter>%
BBefore and LBefore are Bart's and Lisa's percentages over chores 1 to the cut, and BAfter and LAfter are their percentages over the rest of the record. Print every percentage with exactly four digits after the decimal point. A value that sits exactly halfway between two such numbers rounds up. Print a blank line between the outputs of two consecutive records.
Note
Lisa wants the program to show where the before and after percentages support the opposite conclusion from the whole record, so two percentages that print as the same value count as no difference at all. A cut whose two before percentages print the same, or whose two after percentages print the same, is not counted.