解题思路:
注意事项:
参考代码:
import java.awt.print.Book; import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int m = sc.nextInt();//接收几组数据 for (int i = 0; i < m; i++) { int n = sc.nextInt();//小朋友数量 int[][] arr = new int[n][2];//小朋友有的积木数和他一共需要的积木数 for (int j = 0; j < n; j++) { arr[j][0] = sc.nextInt(); arr[j][1] = sc.nextInt(); } Arrays.sort(arr,new Comparator<int[]>(){ public int compare(int[]o1,int[]o2) { return (o1[1]-o1[0])-(o2[1]-o2[0])>0?1:-1; } }); int num = 0; boolean f = true;//假设玩的下去 for (int j = 0; j < n; j++) { //当前小朋友已有的积木数量+积木池的数量>需要的数量 if (arr[j][0]+num>=arr[j][1]) { num+=arr[j][0]; } else { f = false; break; } } if (f == true) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
0.0分
5 人评分
模拟计算器 (C语言代码)浏览:885 |
C二级辅导-计负均正 (C语言代码)浏览:647 |
C语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C语言代码)浏览:1031 |
A+B for Input-Output Practice (IV) (C++代码)浏览:676 |
【明明的随机数】 (C++代码)浏览:779 |
C语言程序设计教程(第三版)课后习题1.5 (C++代码)浏览:757 |
成绩转换 (C语言代码)浏览:1006 |
简单的a+b (C语言代码)浏览:335 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:588 |
C语言程序设计教程(第三版)课后习题12.2 (C语言代码)浏览:753 |