package day131213;
public class WaterCollectionABC {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// 7 3 7-3=4 7-3-3=1 7-(3-1)=5; // 3-(7-5)=1;
//
// a=5 b=3 模(mu):2 模差(md)5-(3-2)=4 //3-(5-4) =2;
System.out.println(ifFulledC(1234567,7654321, 9999999));
//6666673
//246919
}
public static boolean ifFulledC(int a, int b, int c) {
if (a <= 0 || a > 1000000000 || b <= 0 || b > 1000000000 || c <= 0
|| c > 1000000000 || (a%b>c&&b%a>c))
return false;
else {
if (a < b) {
int temp = a;
a = b;
b = temp;
}
if (a == b || a % b == 0) {
System.err.println("ok");
return (c % b == 0);
}
int mu = a % b;//6666673
int md = a - (b - mu);//246919
if (mu < md) {
int temp = mu;
mu = md;
md = temp;
}
// int times= c/md;
for (int i = 0; i <= (c / md)+1; i++) {
for (int j = 0; j <= (c /mu)+1; j++) {
for (int k = 0; k <= (c / b)+1; k++) {
for (int l = 0; l <= (c / a)+1; l++) {
if (i * md + j * mu + k * b + l * a == c)
return true;
}
}
}
}
}
return false;
}
}
做了半天,都没有通过这个题。说用例( 执行测试用例失败!NO! 1234567 7654321 9999999 ok ok ok ok)没通过。不知道是不是我分析错误了。。。纠结中。
题目如下;