全部评论
https://www.nowcoder.com/discuss/82233 去年我做的答案,但是今年怎么都只有 20% 的通过率,我第三题也做出来了,我都怀疑是不是测试用例有问题了
额,你是不是忘了说你的报名科目?
java的话,1->7优先性降低,很简单的 (1)003 (2)111 (3)301 (4)030 (5)220 (6)410 (7)600
package xyz.liuyingdi.test; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNextInt()) { int testTimes = sc.nextInt(); for(int i = 0; i < testTimes; i++) { int n = sc.nextInt(); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); System.out.println(solve(n, a, b, c)); } } } public static String solve(int n, int a, int b, int c) { boolean flag = true; for(int i = 0; i < n; i++) { if(c >= 2) { // 0 0 2 c -= 2; } else if(c >= 1 && b >= 1 && a >= 1) { // 1 1 1 c -= 1; b -= 1; a -= 1; } else if(c >= 1 && a >= 3) { // 3 0 1 c -= 1; a -= 3; } else if(b >= 3) { // 0 3 0 b -= 3; } else if(b >= 2 && a >= 2) { // 2 2 0 b -= 2; a -= 2; } else if(b >= 1 && a >= 4) { // 4 1 0 b -= 1; a -= 4; } else if(a >= 6) { // 6 0 0 a -= 6; } else { flag = false; break; } } String str = flag ? "Yes" : "No"; return str; } }
这题可以动态规划吗
贪心么
package myself; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNextInt()) { int n = sc.nextInt(); int ans = 0, x; int N, A, B, C; for (int i = 0; i < n; i++) { N = sc.nextInt(); A = sc.nextInt(); B = sc.nextInt(); C = sc.nextInt(); N = N - B / 3 - C / 2; B %= 3; C %= 2; if (N <= 0) System.out.println("Yes"); else if ((A + B * 2 + 3 * C < 6 * N) || ((A + B * 2 + 3 * C >= 6 * N) && (A == 0))) System.out.println("No"); else System.out.println("Yes"); } } } }
相关推荐