第一题:100%
int buyCoke(int m, int a, int b, int c, int x) {
int res = 0;
while(m > 0) {
if (c > 0 && c * 100 >= x) {
c -= x / 100;
res += x / 100;
if (x % 100 != 0) {
c -= 1;
res++;
}
b += x % 100 / 50;
a += x % 100 % 50 / 10;
} else if (b > 0 && c * 100 + b * 50 >= x) {
b -= (x - c * 100) / 50;
res += (x - c * 100) / 50;
res += c;
if ((x - c * 100) % 50 != 0) {
b -= 1;
res++;
}
c = 0;
a += (x - c * 100) % 50 / 10;
} else if (a > 0 && b * 50 + a * 10 >= x) {
a -= (x - b * 50) / 10;
res += (x - b * 50) / 10;
res += b;
b = 0;
}
m--;
}
return res;
}
第二题:没做
第三题:return 0; 45%
全部评论
(3) 回帖