Editing
2015 Dec Bronze Problem 3 Contaminated Milk
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Solution == The problem can be solved with a straightforward simulation approach. We can simulate the process in the following steps: * For each milk producer, we can iterate through each time unit and each cow. If the cow drank milk from that producer at that time, and if the cow gets sick at a later time exactly P units away, then we suspect that this milk producer might be the one that produced the contaminated milk. * For each suspected milk producer, we can check if every cow who drank milk from this producer got sick exactly P units after drinking the milk. If so, we confirm this milk producer as a culprit. * Finally, we output the maximum number of cows that got sick from drinking the milk of a confirmed milk producer. This approach will find all the possible milk producers that may have caused the sickness and count the maximum number of cows that could have been infected by each of these producers. The solution runs in a reasonable time since the inputs are relatively small. The key part of this solution is careful implementation: we must keep track of when each cow drank milk from each producer, and when each cow got sick. This can be done with simple array or list structures, with the indices representing the cows or milk producers, and the values representing the times.
Summary:
Please note that all contributions to Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
My wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information