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!
=== Java === <pre> import java.io.*; import java.util.*; public class badmilk { private static int[] personDrink; private static int[] milkDrink; private static int[] timeDrink; private static int[] personSick; private static int[] timeSick; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader("badmilk.in")); PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("badmilk.out"))); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); int d = Integer.parseInt(st.nextToken()); int s = Integer.parseInt(st.nextToken()); initializeDrinkArrays(d, br); initializeSickArrays(s, br); int maxSick = 0; for(int i = 1; i <= m; i++) { if(isMilkBad(i)) { int sickCount = countPeopleWhoDrank(i); maxSick = Math.max(maxSick, sickCount); } } pw.println(maxSick); pw.close(); } private static void initializeDrinkArrays(int d, BufferedReader br) throws IOException { personDrink = new int[d]; milkDrink = new int[d]; timeDrink = new int[d]; for(int i = 0; i < d; i++) { StringTokenizer st = new StringTokenizer(br.readLine()); personDrink[i] = Integer.parseInt(st.nextToken()); milkDrink[i] = Integer.parseInt(st.nextToken()); timeDrink[i] = Integer.parseInt(st.nextToken()); } } private static void initializeSickArrays(int s, BufferedReader br) throws IOException { personSick = new int[s]; timeSick = new int[s]; for(int i = 0; i < s; i++) { StringTokenizer st = new StringTokenizer(br.readLine()); personSick[i] = Integer.parseInt(st.nextToken()); timeSick[i] = Integer.parseInt(st.nextToken()); } } private static boolean isMilkBad(int milkType) { for(int i = 0; i < personSick.length; i++) { if(!didPersonDrinkBefore(personSick[i], milkType, timeSick[i])) { return false; } } return true; } private static boolean didPersonDrinkBefore(int person, int milkType, int time) { for(int i = 0; i < personDrink.length; i++) { if(personDrink[i] == person && milkDrink[i] == milkType && timeDrink[i] < time) { return true; } } return false; } private static int countPeopleWhoDrank(int milkType) { boolean[] didDrink = new boolean[51]; for(int i = 0; i < personDrink.length; i++) { if(milkDrink[i] == milkType) { didDrink[personDrink[i]] = true; } } int drinkCount = 0; for(boolean drank : didDrink) { if(drank) { drinkCount++; } } return drinkCount; } } </pre>
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