Created
July 2, 2012 03:56
-
-
Save kunishi/3030980 to your computer and use it in GitHub Desktop.
ACM International Collegiate Programming Contest, Asia Regional (Tokyo), 2004, Problem A
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.util.Scanner; | |
public class Asia2004A { | |
public static void main(String[] args) throws FileNotFoundException { | |
int a, b, d; | |
Scanner s = new Scanner(new File(args[0])); | |
while (true) { | |
a = s.nextInt(); | |
b = s.nextInt(); | |
d = s.nextInt(); | |
if (a == 0 && b == 0 && d == 0) { | |
break; | |
} | |
// processing | |
int x = 0, y = 0, num = 0; | |
int maxsum = 0; | |
boolean found = false; | |
while (!found) { | |
num++; | |
maxsum = 0; | |
for (int i = 0; i <= num; i++) { | |
if (a * i - b * (num - i) == d || | |
b * (num - i) - a * i == d || | |
a * i + b * (num - i) == d) { | |
found = true; | |
if (maxsum == 0 || | |
a * i + b + (num - i) < maxsum) { | |
x = i; | |
y = num - i; | |
maxsum = a * i + b * (num - i); | |
} | |
} | |
} | |
} | |
System.out.println(x + " " + y); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment