NC547 三色球
三色球
解题思路:
1)找出a、b、c中的最小值即为res基数;
2)a,b,c,分别减去res;
3)剩下的根据公式逐次计算补齐颜色值(注意,2个红气球+1个黄气球可以兑换1个蓝气球,意味着3个红色气球和2个黄色气球可以兑换一张彩票)
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 三色球 * @param a int整型 * @param b int整型 * @param c int整型 * @return int整型 */ int solve(int a, int b, int c) { // write code here int res = min(a, b); res = min(res, c); a -= res; b -= res; c -= res; if (a == 0) { while (b > 0 && c > 0) { b -= 3; c -= 2; res++; } if (b < 0 || c < 0) { res--; } }else if (b == 0) { while (a > 0 && c > 0) { c -= 3; a -= 2; res++; } if (a < 0 || c < 0) { res--; } }else if (c == 0) { while (a > 0 && b > 0) { a -= 3; b -= 2; res++; } if (a < 0 || b < 0) { res--; } } return res; } };